home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / x / volume6 / xldimage / patch3.1-2 next >
Encoding:
Internet Message Format  |  1990-02-27  |  84.0 KB

  1. Path: uunet!cs.utexas.edu!samsung!uakari.primate.wisc.edu!ames!sun-barr!newstop!sun!turnpike!argv
  2. From: argv%turnpike@Sun.COM (Dan Heller)
  3. Newsgroups: comp.sources.x
  4. Subject: v06i001: Xloadimage, Patch 3, Part 01/02
  5. Message-ID: <132315@sun.Eng.Sun.COM>
  6. Date: 28 Feb 90 09:39:45 GMT
  7. Sender: news@sun.Eng.Sun.COM
  8. Lines: 2719
  9. Approved: argv@sun.com
  10.  
  11. Posting-number: Volume 6, Issue 1
  12. Submitted-by: Jim Frost <jimf@saber.com>
  13. Archive-name: xldimage/patch3.1-2
  14. Patch-To: xldimage: Volume 5, Issue 27-28,30
  15.  
  16. This is part 1 of a 2 part patch to xloadimage to bring it from
  17. patchlevel 02 to patchlevel 03.
  18.  
  19. There are many bug fixes and improvements in patchlevel 03, including
  20. a new loader for GIF images.  This version should work on most X
  21. servers, including those with depths of odd values such as 2 or 4 (eg
  22. 386/ix servers).  See the README file for more information.
  23.  
  24. Part 1, which follows, contains a patch file which should be applied
  25. to a virgin patchlevel 02 source directory.  Save it in the file
  26. "patch.03" and apply via "patch < patch.03".
  27.  
  28. Part 2 contains a shar file with the new GIF loader and associated
  29. header files.  Save it in the file "patch.03.shar" and unpack it via
  30. "sh patch.03.shar".
  31.  
  32. If you do not have xloadimage or do not have it updated to patchlevel
  33. 02, you can get the original source (distributed at patchlevel 01) and
  34. the 02 patch from the comp.sources.x archives, or you can get the full
  35. distribution from expo.lcs.mit.edu in /contrib/xloadimage.1.03.tar.Z
  36. via anonymous ftp.  The original source and 02 patch are also on expo
  37. but have been moved to /oldcontrib.
  38.  
  39. Feel free to email any questions or comments.
  40.  
  41. Enjoy,
  42.  
  43. jim frost
  44. saber software
  45. jimf@saber.com
  46.  
  47. -- patch.03: cut here --
  48. diff -c xloadimage.02/Imakefile xloadimage.03/Imakefile
  49. *** xloadimage.02/Imakefile    Sun Dec 31 16:03:09 1989
  50. --- xloadimage.03/Imakefile    Wed Dec 13 15:18:47 1989
  51. ***************
  52. *** 3,14 ****
  53.           DEPLIBS = $(DEPLIBS)
  54.   LOCAL_LIBRARIES = $(XLIB)
  55.              SRCS = bright.c clip.c compress.c dither.c faces.c fill.c \
  56. !           halftone.c imagetypes.c merge.c misc.c new.c \
  57.             options.c path.c pbm.c reduce.c root.c send.c \
  58.             sunraster.c value.c window.c xbitmap.c xloadimage.c \
  59.             xpixmap.c zio.c zoom.c
  60.              OBJS = bright.o clip.o compress.o dither.o faces.o fill.o \
  61. !           halftone.o imagetypes.o merge.o misc.o new.o \
  62.             options.o path.o pbm.o reduce.o root.o send.o \
  63.             sunraster.o value.o window.o xbitmap.o xloadimage.o \
  64.             xpixmap.o zio.o zoom.o
  65. --- 3,14 ----
  66.           DEPLIBS = $(DEPLIBS)
  67.   LOCAL_LIBRARIES = $(XLIB)
  68.              SRCS = bright.c clip.c compress.c dither.c faces.c fill.c \
  69. !           gif.c halftone.c imagetypes.c merge.c misc.c new.c \
  70.             options.c path.c pbm.c reduce.c root.c send.c \
  71.             sunraster.c value.c window.c xbitmap.c xloadimage.c \
  72.             xpixmap.c zio.c zoom.c
  73.              OBJS = bright.o clip.o compress.o dither.o faces.o fill.o \
  74. !           gif.o halftone.o imagetypes.o merge.o misc.o new.o \
  75.             options.o path.o pbm.o reduce.o root.o send.o \
  76.             sunraster.o value.o window.o xbitmap.o xloadimage.o \
  77.             xpixmap.o zio.o zoom.o
  78. diff -c xloadimage.02/Makefile.gcc xloadimage.03/Makefile.gcc
  79. *** xloadimage.02/Makefile.gcc    Sun Dec 31 16:03:09 1989
  80. --- xloadimage.03/Makefile.gcc    Wed Jan  3 15:30:20 1990
  81. ***************
  82. *** 1,6 ****
  83.   # Makefile for xloadimage using GNU C compiler
  84.   #
  85. ! # Copyright 1989 Jim Frost
  86.   #
  87.   # See file "copyright.h" for complete copyright information.
  88.   
  89. --- 1,6 ----
  90.   # Makefile for xloadimage using GNU C compiler
  91.   #
  92. ! # Copyright 1989, 1990 Jim Frost
  93.   #
  94.   # See file "copyright.h" for complete copyright information.
  95.   
  96. ***************
  97. *** 8,14 ****
  98.   CFLAGS= -O -fstrength-reduce -finline-functions -DSYSPATHFILE=\"/usr/lib/xloadimagerc\"
  99.   
  100.   LIBS= -lX11
  101. ! OBJS= bright.o clip.o compress.o dither.o faces.o fill.o \
  102.         halftone.o imagetypes.o merge.o misc.o new.o options.o path.o \
  103.         pbm.o reduce.o root.o send.o sunraster.o value.o window.o \
  104.         xbitmap.o xloadimage.o xpixmap.o zio.o zoom.o
  105. --- 8,14 ----
  106.   CFLAGS= -O -fstrength-reduce -finline-functions -DSYSPATHFILE=\"/usr/lib/xloadimagerc\"
  107.   
  108.   LIBS= -lX11
  109. ! OBJS= bright.o clip.o compress.o dither.o faces.o fill.o gif.o \
  110.         halftone.o imagetypes.o merge.o misc.o new.o options.o path.o \
  111.         pbm.o reduce.o root.o send.o sunraster.o value.o window.o \
  112.         xbitmap.o xloadimage.o xpixmap.o zio.o zoom.o
  113. diff -c xloadimage.02/Makefile.std xloadimage.03/Makefile.std
  114. *** xloadimage.02/Makefile.std    Sun Dec 31 16:03:10 1989
  115. --- xloadimage.03/Makefile.std    Wed Jan  3 15:30:10 1990
  116. ***************
  117. *** 1,6 ****
  118.   # Makefile for xloadimage using standard C compiler
  119.   #
  120. ! # Copyright 1989 Jim Frost
  121.   #
  122.   # See file "copyright.h" for complete copyright information.
  123.   
  124. --- 1,6 ----
  125.   # Makefile for xloadimage using standard C compiler
  126.   #
  127. ! # Copyright 1989, 1990 Jim Frost
  128.   #
  129.   # See file "copyright.h" for complete copyright information.
  130.   
  131. ***************
  132. *** 8,14 ****
  133.   CFLAGS= -O -DSYSPATHFILE=\"/usr/lib/xloadimagerc\"
  134.   
  135.   LIBS= -lX11
  136. ! OBJS= bright.o clip.o compress.o dither.o faces.o fill.o \
  137.         halftone.o imagetypes.o merge.o misc.o new.o options.o path.o \
  138.         pbm.o reduce.o root.o send.o sunraster.o value.o window.o \
  139.         xbitmap.o xloadimage.o xpixmap.o zio.o zoom.o
  140. --- 8,14 ----
  141.   CFLAGS= -O -DSYSPATHFILE=\"/usr/lib/xloadimagerc\"
  142.   
  143.   LIBS= -lX11
  144. ! OBJS= bright.o clip.o compress.o dither.o faces.o fill.o gif.o \
  145.         halftone.o imagetypes.o merge.o misc.o new.o options.o path.o \
  146.         pbm.o reduce.o root.o send.o sunraster.o value.o window.o \
  147.         xbitmap.o xloadimage.o xpixmap.o zio.o zoom.o
  148. diff -c xloadimage.02/README xloadimage.03/README
  149. *** xloadimage.02/README    Sun Dec 31 16:03:16 1989
  150. --- xloadimage.03/README    Wed Jan  3 12:41:10 1990
  151. ***************
  152. *** 3,41 ****
  153.   WHAT IS IT?
  154.   
  155.   This utility will view several types of images under X11, or load
  156. ! images onto the root window.  The current version supports X11 Bitmap,
  157. ! Portable Bitmap, Faces Project, and Sun Rasterfile images.  More are
  158. ! planned.
  159.   
  160.   A variety of options are available to modify images prior to viewing.
  161.   These options include clipping, dithering, depth reduction, zoom
  162. ! (either X or Y axis independently or both at once),
  163. ! brightening/darkening, and image merging.  When applicable, these
  164. ! options are done automatically (eg a color image to be displayed on a
  165. ! monochrome screen will be dithered automatically).
  166.   
  167. - IMPLEMENTATION
  168. - Most functions are not particularly fast, and some functions use
  169. - simple-minded algorithms deliberately over more advanced ones.  I
  170. - stressed portability over all and simplicity over performance.  I
  171. - believe the result is a usable, portable tool which should serve the
  172. - needs of most users.
  173. - The source code is basically in two parts: image manipulation routines
  174. - and everything else.  The image manipulation routines should be
  175. - completely independent of X, thus allowing people to use them under
  176. - other graphical systems.  No guarantees here, but I tried.
  177. - Performance-oriented people will notice that when loading a color
  178. - image, the colormap of the image is minimized (and all pixel values in
  179. - the image changed), then the colormap is redone (and all pixel values
  180. - in the image changed again) before sending to X.  This could be
  181. - reduced to only one remapping of the image but I wanted to keep the
  182. - image from X's grubby (greedy?) hands as long as possible, and the
  183. - image merging function really wants the image to have a minimized
  184. - colormap.
  185.   COMPILING
  186.   
  187.   There are three ways to compile xloadimage, depending on what
  188. --- 3,24 ----
  189.   WHAT IS IT?
  190.   
  191.   This utility will view several types of images under X11, or load
  192. ! images onto the root window.  The current version supports:
  193.   
  194. +     Faces Project
  195. +     GIF
  196. +     Portable Bitmap (PBM)
  197. +     Sun Rasterfile
  198. +     X11 Bitmap
  199. +     X Pixmap
  200.   A variety of options are available to modify images prior to viewing.
  201.   These options include clipping, dithering, depth reduction, zoom
  202. ! (either X or Y axis independently or both at once), brightening or
  203. ! darkening, and image merging.  When applicable, these options are done
  204. ! automatically (eg a color image to be displayed on a monochrome screen
  205. ! will be dithered automatically).
  206.   
  207.   COMPILING
  208.   
  209.   There are three ways to compile xloadimage, depending on what
  210. ***************
  211. *** 59,71 ****
  212.   After compiling and installing xloadimage, I recommend linking or
  213.   symlinking to the executable with the names "xview" and "xsetbg".  The
  214.   default behavior is slightly different when invoked with these
  215. ! commands (they're also easier to type).
  216.   
  217.   OWNERSHIP
  218.   
  219. ! I used the MIT X Consortium copyright with all of these functions,
  220. ! thereby allowing full freedom with the code so long as the copyright
  221. ! notices remain intact.  Free code can be good code.
  222.   
  223.   SUGGESTIONS AND BUG REPORTS
  224.   
  225. --- 42,80 ----
  226.   After compiling and installing xloadimage, I recommend linking or
  227.   symlinking to the executable with the names "xview" and "xsetbg".  The
  228.   default behavior is slightly different when invoked with these
  229. ! commands (they're also easier to type).  If you have a public image
  230. ! area you should consider setting the SYSPATHFILE option in the
  231. ! makefile and setting up a system-wide configuration file.  See the man
  232. ! page for information on the format of this file.
  233.   
  234. + IMPLEMENTATION
  235. + Most functions are not particularly fast, and some functions use
  236. + simple-minded algorithms deliberately over more advanced ones.  I
  237. + stressed portability over all and simplicity over performance.  I
  238. + believe the result is a usable, portable tool which should serve the
  239. + needs of most users.
  240. + The source code is basically in two parts: image manipulation routines
  241. + and everything else.  The image manipulation routines should be
  242. + completely independent of X, thus allowing people to use them under
  243. + other graphical systems.  No guarantees here, but I tried.
  244. + Performance-oriented people will notice that when loading a color
  245. + image, the colormap of the image is minimized (and all pixel values in
  246. + the image changed), then the colormap is redone (and all pixel values
  247. + in the image changed again) before sending to X.  This could be
  248. + reduced to only one remapping of the image but I wanted to keep the
  249. + image from X's grubby (greedy?) hands as long as possible, and the
  250. + image merging function really wants the image to have a minimized
  251. + colormap.
  252.   OWNERSHIP
  253.   
  254. ! I used a modified version of the MIT X Consortium copyright with all
  255. ! of these functions, thereby allowing full freedom with the code so
  256. ! long as the copyright notices remain intact.  Free code can be good
  257. ! code.  All contributions have similar notices.
  258.   
  259.   SUGGESTIONS AND BUG REPORTS
  260.   
  261. ***************
  262. *** 72,91 ****
  263.   Suggestions and bug reports should go to:
  264.   
  265.       Jim Frost
  266. !     madd@std.com
  267. !     ..uunet!world!madd
  268.   
  269.   Please include the version number and sample image data if you are
  270.   reporting a bug.
  271.   
  272.   Functions implementing new image types are welcomed; mail them to the
  273. ! same address and I'll do my best to distribute them.
  274.   
  275.   THANKS
  276.   
  277.   Special thanks to the crew at the Boston University Graphics Lab for
  278.   their assistance and sample images, and to bzs@std.com for his simple
  279. ! dithering algorithm (or what's left of it).
  280.   
  281.   HISTORY
  282.   
  283. --- 81,108 ----
  284.   Suggestions and bug reports should go to:
  285.   
  286.       Jim Frost
  287. !     jimf@saber.com
  288. !     ..harvard!saber!jimf
  289.   
  290.   Please include the version number and sample image data if you are
  291.   reporting a bug.
  292.   
  293.   Functions implementing new image types are welcomed; mail them to the
  294. ! same address and I'll do my best to distribute them.  Try do send them
  295. ! as public domain so I can keep the number of differing copyright
  296. ! messages to a minimum -- I'll use my standard message and leave the
  297. ! implementor's name and information in the file for credit.  I wouldn't
  298. ! copyright this stuff at all except that it's a requirement for X11
  299. ! distribution.
  300.   
  301.   THANKS
  302.   
  303.   Special thanks to the crew at the Boston University Graphics Lab for
  304.   their assistance and sample images, and to bzs@std.com for his simple
  305. ! dithering algorithm (or what's left of it).  Real special thanks to
  306. ! Kirk L. Johnson (tuna@athena.mit.edu) for a very nice GIF loader, and
  307. ! to Mark Snitily (zok!mark@apple.com) for 386/ix compatibility work and
  308. ! miscellaneous bug-tracking.
  309.   
  310.   HISTORY
  311.   
  312. ***************
  313. *** 103,105 ****
  314. --- 120,132 ----
  315.   the image up (with the old one moved to halftone.c), and a bug fix to
  316.   zoom.c to correct problems when zooming bitmaps.
  317.   
  318. + Patch 03 contained a new loader for GIF files.  The dither bits array
  319. + in dither.c was changed so it worked properly, and both dither.c and
  320. + halftone.c had minor bugs fixed.  Merge.c was modified to correct bugs
  321. + when merging RGB images.  Pbm.c was modified to handle raw format
  322. + images.  Root.c was modified to deny image loads which would change
  323. + the root window's colormap.  Send.c was modified to use shared colors
  324. + whenever possible and to handle color displays which have depths which
  325. + are not a multiple of 8.  Window.c was modified to avoid deleting the
  326. + default colormap, allowing proper operation on some servers prior to
  327. + X11R3 patchlevel 08.  There were many miscellaneous bug fixes.
  328. diff -c xloadimage.02/bright.c xloadimage.03/bright.c
  329. *** xloadimage.02/bright.c    Mon Nov  6 10:51:07 1989
  330. --- xloadimage.03/bright.c    Wed Dec  6 14:54:17 1989
  331. ***************
  332. *** 13,19 ****
  333.   
  334.   void brighten(image, percent, verbose)
  335.        Image        *image;
  336. !      int           percent;
  337.        unsigned int  verbose;
  338.   { int          a;
  339.     unsigned int newrgb;
  340. --- 13,19 ----
  341.   
  342.   void brighten(image, percent, verbose)
  343.        Image        *image;
  344. !      unsigned int  percent;
  345.        unsigned int  verbose;
  346.   { int          a;
  347.     unsigned int newrgb;
  348. diff -c xloadimage.02/compress.c xloadimage.03/compress.c
  349. *** xloadimage.02/compress.c    Mon Nov  6 10:51:09 1989
  350. --- xloadimage.03/compress.c    Wed Jan  3 15:31:07 1990
  351. ***************
  352. *** 4,11 ****
  353.    *
  354.    * jim frost 10.05.89
  355.    *
  356. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  357. !  * copyright information.
  358.    */
  359.   
  360.   #include "copyright.h"
  361. --- 4,11 ----
  362.    *
  363.    * jim frost 10.05.89
  364.    *
  365. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  366. !  * complete copyright information.
  367.    */
  368.   
  369.   #include "copyright.h"
  370. diff -c xloadimage.02/copyright.h xloadimage.03/copyright.h
  371. *** xloadimage.02/copyright.h    Mon Nov  6 10:51:10 1989
  372. --- xloadimage.03/copyright.h    Wed Jan  3 15:36:59 1990
  373. ***************
  374. *** 1,6 ****
  375.   #ifndef _JIM_COPYRIGHT_
  376.   /*
  377. !  * Copyright 1989 Jim Frost
  378.    *
  379.    * Permission to use, copy, modify, distribute, and sell this software
  380.    * and its documentation for any purpose is hereby granted without fee,
  381. --- 1,6 ----
  382.   #ifndef _JIM_COPYRIGHT_
  383.   /*
  384. !  * Copyright 1989, 1990 Jim Frost
  385.    *
  386.    * Permission to use, copy, modify, distribute, and sell this software
  387.    * and its documentation for any purpose is hereby granted without fee,
  388. diff -c xloadimage.02/dither.c xloadimage.03/dither.c
  389. *** xloadimage.02/dither.c    Sun Dec 31 16:03:11 1989
  390. --- xloadimage.03/dither.c    Wed Jan  3 15:31:22 1990
  391. ***************
  392. *** 7,13 ****
  393.    * jim frost 07.10.89
  394.    * Steve Losen 11.17.89
  395.    *
  396. !  * Copyright 1989 Jim Frost and Steve Losen.  See included file
  397.    * "copyright.h" for complete copyright information.
  398.    */
  399.   
  400. --- 7,13 ----
  401.    * jim frost 07.10.89
  402.    * Steve Losen 11.17.89
  403.    *
  404. !  * Copyright 1989, 1990 Jim Frost and Steve Losen.  See included file
  405.    * "copyright.h" for complete copyright information.
  406.    */
  407.   
  408. ***************
  409. *** 22,42 ****
  410.   
  411.   static byte DitherBits[GRAYS][4] = {
  412.     0xf, 0xf, 0xf, 0xf,
  413. !   0xf, 0xf, 0xf, 0x7,
  414. !   0xf, 0xf, 0xf, 0x3,
  415. !   0xf, 0xf, 0x7, 0x3,
  416. !   0xf, 0xf, 0x3, 0x3,
  417. !   0xf, 0xf, 0x3, 0x1,
  418. !   0xf, 0x7, 0x3, 0x1,
  419. !   0xf, 0x7, 0x1, 0x1,
  420. !   0x7, 0x7, 0x3, 0x0,
  421. !   0x7, 0x7, 0x1, 0x0,
  422. !   0x7, 0x3, 0x1, 0x0,
  423. !   0x7, 0x3, 0x0, 0x0,
  424. !   0x3, 0x3, 0x0, 0x0,
  425. !   0x3, 0x1, 0x0, 0x0,
  426. !   0x3, 0x0, 0x0, 0x0,
  427. !   0x1, 0x0, 0x0, 0x0,
  428.     0x0, 0x0, 0x0, 0x0
  429.   };
  430.   
  431. --- 22,42 ----
  432.   
  433.   static byte DitherBits[GRAYS][4] = {
  434.     0xf, 0xf, 0xf, 0xf,
  435. !   0xe, 0xf, 0xf, 0xf,
  436. !   0xe, 0xf, 0xb, 0xf,
  437. !   0xa, 0xf, 0xb, 0xf,
  438. !   0xa, 0xf, 0xa, 0xf,
  439. !   0xa, 0xd, 0xa, 0xf,
  440. !   0xa, 0xd, 0xa, 0x7,
  441. !   0xa, 0x5, 0xa, 0x7,
  442. !   0xa, 0x5, 0xa, 0x5,
  443. !   0x8, 0x5, 0xa, 0x5,
  444. !   0x8, 0x5, 0x2, 0x5,
  445. !   0x0, 0x5, 0x2, 0x5,
  446. !   0x0, 0x5, 0x0, 0x5,
  447. !   0x0, 0x4, 0x0, 0x5,
  448. !   0x0, 0x4, 0x0, 0x1,
  449. !   0x0, 0x0, 0x0, 0x1,
  450.     0x0, 0x0, 0x0, 0x0
  451.   };
  452.   
  453. ***************
  454. *** 47,59 ****
  455.        Image        *cimage;
  456.        unsigned int  verbose;
  457.   { Image         *image;
  458. !   unsigned char *sp, *dp, *dp2; /* data pointers */
  459. !   unsigned int   dindex;        /* index into dither array */
  460. !   unsigned int   spl;           /* source pixel length in bytes */
  461. !   unsigned int   dll;           /* destination line length in bytes */
  462. !   Pixel          color;         /* pixel color */
  463. !   unsigned int  *index;         /* index into dither array for a given pixel */
  464. !   unsigned int   a, x, y;       /* random counters */
  465.   
  466.     goodImage(cimage, "dither");
  467.     if (! RGBP(cimage))
  468. --- 47,59 ----
  469.        Image        *cimage;
  470.        unsigned int  verbose;
  471.   { Image         *image;
  472. !   unsigned char *sp, *dp; /* data pointers */
  473. !   unsigned int   dindex;  /* index into dither array */
  474. !   unsigned int   spl;     /* source pixel length in bytes */
  475. !   unsigned int   dll;     /* destination line length in bytes */
  476. !   Pixel          color;   /* pixel color */
  477. !   unsigned int  *index;   /* index into dither array for a given pixel */
  478. !   unsigned int   x, y;    /* random counters */
  479.   
  480.     goodImage(cimage, "dither");
  481.     if (! RGBP(cimage))
  482. ***************
  483. *** 84,94 ****
  484.   
  485.     if (cimage->depth <= 16) {
  486.       index= (unsigned int *)malloc(sizeof(unsigned int) * cimage->rgb.used);
  487. !     for (x= 0; x < cimage->rgb.used; x++)
  488.         *(index + x)=
  489.       ((unsigned long)(*(cimage->rgb.red + x)) +
  490.        *(cimage->rgb.green + x) +
  491.        *(cimage->rgb.blue + x)) / GRAYSTEP;
  492.     }
  493.     else
  494.       index= NULL;
  495. --- 84,97 ----
  496.   
  497.     if (cimage->depth <= 16) {
  498.       index= (unsigned int *)malloc(sizeof(unsigned int) * cimage->rgb.used);
  499. !     for (x= 0; x < cimage->rgb.used; x++) {
  500.         *(index + x)=
  501.       ((unsigned long)(*(cimage->rgb.red + x)) +
  502.        *(cimage->rgb.green + x) +
  503.        *(cimage->rgb.blue + x)) / GRAYSTEP;
  504. +       if (*(index + x) >= GRAYS)
  505. +     *(index + x)= GRAYS - 1;
  506. +     }
  507.     }
  508.     else
  509.       index= NULL;
  510. ***************
  511. *** 103,112 ****
  512.         color= memToVal(sp, spl);
  513.         if (index)
  514.       dindex= *(index + color);
  515. !       else
  516.       dindex= ((unsigned long)(*(cimage->rgb.red + color)) +
  517.            *(cimage->rgb.green + color) +
  518.            *(cimage->rgb.blue + color)) / GRAYSTEP;
  519.         if (DitherBits[dindex][y & 3] & (1 << (x & 3)))
  520.        dp[x / 8] |= 1 << (7 - (x & 7));
  521.         sp += spl;
  522. --- 106,118 ----
  523.         color= memToVal(sp, spl);
  524.         if (index)
  525.       dindex= *(index + color);
  526. !       else {
  527.       dindex= ((unsigned long)(*(cimage->rgb.red + color)) +
  528.            *(cimage->rgb.green + color) +
  529.            *(cimage->rgb.blue + color)) / GRAYSTEP;
  530. +     if (dindex >= GRAYS)
  531. +       dindex= GRAYS - 1;
  532. +       }
  533.         if (DitherBits[dindex][y & 3] & (1 << (x & 3)))
  534.        dp[x / 8] |= 1 << (7 - (x & 7));
  535.         sp += spl;
  536. Only in xloadimage.03: gif.c
  537. Only in xloadimage.03: gif.h
  538. diff -c xloadimage.02/halftone.c xloadimage.03/halftone.c
  539. *** xloadimage.02/halftone.c    Sun Dec 31 16:01:50 1989
  540. --- xloadimage.03/halftone.c    Wed Jan  3 15:36:35 1990
  541. ***************
  542. *** 6,13 ****
  543.    *
  544.    * jim frost 07.10.89
  545.    *
  546. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  547. !  * copyright information.
  548.    */
  549.   
  550.   #include "copyright.h"
  551. --- 6,13 ----
  552.    *
  553.    * jim frost 07.10.89
  554.    *
  555. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  556. !  * complete copyright information.
  557.    */
  558.   
  559.   #include "copyright.h"
  560. ***************
  561. *** 62,68 ****
  562.      */
  563.   
  564.     if (verbose) {
  565. !     printf("  Dithering image...");
  566.       fflush(stdout);
  567.     }
  568.     image= newBitImage(cimage->width * 4, cimage->height * 4);
  569. --- 62,68 ----
  570.      */
  571.   
  572.     if (verbose) {
  573. !     printf("  Halftoning image...");
  574.       fflush(stdout);
  575.     }
  576.     image= newBitImage(cimage->width * 4, cimage->height * 4);
  577. ***************
  578. *** 83,93 ****
  579.   
  580.     if (cimage->depth <= 16) {
  581.       index= (unsigned int *)malloc(sizeof(unsigned int) * cimage->rgb.used);
  582. !     for (x= 0; x < cimage->rgb.used; x++)
  583.         *(index + x)=
  584.       ((unsigned long)(*(cimage->rgb.red + x)) +
  585.        *(cimage->rgb.green + x) +
  586.        *(cimage->rgb.blue + x)) / GRAYSTEP;
  587.     }
  588.     else
  589.       index= NULL;
  590. --- 83,96 ----
  591.   
  592.     if (cimage->depth <= 16) {
  593.       index= (unsigned int *)malloc(sizeof(unsigned int) * cimage->rgb.used);
  594. !     for (x= 0; x < cimage->rgb.used; x++) {
  595.         *(index + x)=
  596.       ((unsigned long)(*(cimage->rgb.red + x)) +
  597.        *(cimage->rgb.green + x) +
  598.        *(cimage->rgb.blue + x)) / GRAYSTEP;
  599. +       if (*(index + x) >= GRAYS) /* rounding errors can do this */
  600. +     *(index + x)= GRAYS - 1;
  601. +     }
  602.     }
  603.     else
  604.       index= NULL;
  605. ***************
  606. *** 103,112 ****
  607.         color= memToVal(sp, spl);
  608.         if (index)
  609.       dindex= *(index + color);
  610. !       else
  611.       dindex= ((unsigned long)(*(cimage->rgb.red + color)) +
  612.            *(cimage->rgb.green + color) +
  613.            *(cimage->rgb.blue + color)) / GRAYSTEP;
  614.   
  615.         /* loop for the four Y bits in the dither pattern, putting all
  616.          * four X bits in at once.  if you think this would be hard to
  617. --- 106,118 ----
  618.         color= memToVal(sp, spl);
  619.         if (index)
  620.       dindex= *(index + color);
  621. !       else {
  622.       dindex= ((unsigned long)(*(cimage->rgb.red + color)) +
  623.            *(cimage->rgb.green + color) +
  624.            *(cimage->rgb.blue + color)) / GRAYSTEP;
  625. +     if (dindex >= GRAYS) /* rounding errors can do this */
  626. +       dindex= GRAYS - 1;
  627. +       }
  628.   
  629.         /* loop for the four Y bits in the dither pattern, putting all
  630.          * four X bits in at once.  if you think this would be hard to
  631. diff -c xloadimage.02/image.h xloadimage.03/image.h
  632. *** xloadimage.02/image.h    Sun Dec 31 16:03:11 1989
  633. --- xloadimage.03/image.h    Wed Dec  6 15:12:34 1989
  634. ***************
  635. *** 56,63 ****
  636. --- 56,69 ----
  637.   
  638.   Image *clip(); /* clip.c */
  639.   
  640. + void brighten(); /* bright.c */
  641. + void compress(); /* compress.c */
  642.   Image *dither(); /* dither.c */
  643.   
  644. + void fill(); /* fill.c */
  645.   void fold(); /* fold.c */
  646.   
  647.   Image *halftone(); /* halftone.c */
  648. ***************
  649. *** 66,72 ****
  650.   void   identifyImage();
  651.   void   goodImage();
  652.   
  653. ! Image *mergeImages(); /* merge.c */
  654.   
  655.   char  *dupString(); /* new.c */
  656.   Image *newBitImage();
  657. --- 72,78 ----
  658.   void   identifyImage();
  659.   void   goodImage();
  660.   
  661. ! void merge(); /* merge.c */
  662.   
  663.   char  *dupString(); /* new.c */
  664.   Image *newBitImage();
  665. ***************
  666. *** 82,90 ****
  667. --- 88,100 ----
  668.   void reduceRGBMap(); /* reduce.c */
  669.   void reduce();
  670.   
  671. + void imageOnRoot(); /* root.c */
  672.   unsigned long memToVal(); /* value.c */
  673.   void          valToMem();
  674.   unsigned long memToValLSB();
  675.   void          valToMemLSB();
  676. + void imageInWindow(); /* window.c */
  677.   
  678.   Image *zoom(); /* zoom.c */
  679. diff -c xloadimage.02/imagetypes.h xloadimage.03/imagetypes.h
  680. *** xloadimage.02/imagetypes.h    Sun Dec 31 16:03:12 1989
  681. --- xloadimage.03/imagetypes.h    Wed Dec 13 15:21:36 1989
  682. ***************
  683. *** 10,15 ****
  684. --- 10,16 ----
  685.   Image *facesLoad();
  686.   Image *pbmLoad();
  687.   Image *sunRasterLoad();
  688. + Image *gifLoad();
  689.   Image *xbitmapLoad();
  690.   Image *xpixmapLoad();
  691.   
  692. ***************
  693. *** 16,21 ****
  694. --- 17,23 ----
  695.   int facesIdent();
  696.   int pbmIdent();
  697.   int sunRasterIdent();
  698. + int gifIdent();
  699.   int xbitmapIdent();
  700.   int xpixmapIdent();
  701.   
  702. ***************
  703. *** 30,35 ****
  704. --- 32,38 ----
  705.     sunRasterIdent, sunRasterLoad, "Sun Rasterfile",
  706.     pbmIdent,       pbmLoad,       "Portable Bit Map (PBM)",
  707.     facesIdent,     facesLoad,     "Faces Project",
  708. +   gifIdent,       gifLoad,       "GIF Image",
  709.     xpixmapIdent,   xpixmapLoad,   "X Pixmap",
  710.     xbitmapIdent,   xbitmapLoad,   "X Bitmap",
  711.     NULL,           NULL,          NULL
  712. Only in xloadimage.03: kljcpyrght.h
  713. diff -c xloadimage.02/merge.c xloadimage.03/merge.c
  714. *** xloadimage.02/merge.c    Mon Nov  6 10:51:20 1989
  715. --- xloadimage.03/merge.c    Wed Jan  3 15:32:16 1990
  716. ***************
  717. *** 4,11 ****
  718.    *
  719.    * jim frost 09.27.89
  720.    *
  721. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  722. !  * copyright information.
  723.    */
  724.   
  725.   #include "copyright.h"
  726. --- 4,11 ----
  727.    *
  728.    * jim frost 09.27.89
  729.    *
  730. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  731. !  * complete copyright information.
  732.    */
  733.   
  734.   #include "copyright.h"
  735. ***************
  736. *** 20,38 ****
  737.     if (dest->rgb.used + src->rgb.used > dest->rgb.size) {
  738.       newRGBMapData(&newcolors, dest->rgb.used + src->rgb.used);
  739.       newcolors.used= newcolors.size;
  740. !     for (a= 0, b= 0; a < dest->rgb.used; a++, b++) {
  741. !       *(newcolors.red + b)= *(dest->rgb.red + a);
  742. !       *(newcolors.green + b)= *(dest->rgb.green + a);
  743. !       *(newcolors.blue + b)= *(dest->rgb.blue + a);
  744.       }
  745. !     for (b= 0; a < src->rgb.used; a++, b++) {
  746. !       *(newcolors.red + b)= *(src->rgb.red + a);
  747. !       *(newcolors.green + b)= *(src->rgb.green + a);
  748. !       *(newcolors.blue + b)= *(src->rgb.blue + a);
  749.       }
  750.   
  751.       reduceRGBMap(&newcolors, dest->rgb.size, verbose);
  752. -     dest->rgb.used= dest->rgb.size;
  753.       
  754.       for (a= 0; a < dest->rgb.used; a++) {             /* put new colors into */
  755.         *(dest->rgb.red + a)= *(newcolors.red + a);     /* old colormaps */
  756. --- 20,37 ----
  757.     if (dest->rgb.used + src->rgb.used > dest->rgb.size) {
  758.       newRGBMapData(&newcolors, dest->rgb.used + src->rgb.used);
  759.       newcolors.used= newcolors.size;
  760. !     for (a= 0; a < dest->rgb.used; a++) {
  761. !       *(newcolors.red + a)= *(dest->rgb.red + a);
  762. !       *(newcolors.green + a)= *(dest->rgb.green + a);
  763. !       *(newcolors.blue + a)= *(dest->rgb.blue + a);
  764.       }
  765. !     for (b= 0; b < src->rgb.used; a++, b++) {
  766. !       *(newcolors.red + a)= *(src->rgb.red + b);
  767. !       *(newcolors.green + a)= *(src->rgb.green + b);
  768. !       *(newcolors.blue + a)= *(src->rgb.blue + b);
  769.       }
  770.   
  771.       reduceRGBMap(&newcolors, dest->rgb.size, verbose);
  772.       
  773.       for (a= 0; a < dest->rgb.used; a++) {             /* put new colors into */
  774.         *(dest->rgb.red + a)= *(newcolors.red + a);     /* old colormaps */
  775. ***************
  776. *** 44,50 ****
  777.         *(src->rgb.green + a)= *(newcolors.green + a + dest->rgb.used);
  778.         *(src->rgb.blue + a)= *(newcolors.blue + a + dest->rgb.used);
  779.       }
  780. -     freeRGBMapData(&newcolors);
  781.     }
  782.     else
  783.       for (a= 0; a < src->rgb.used; a++, (dest->rgb.used)++) {
  784. --- 43,48 ----
  785. ***************
  786. *** 136,142 ****
  787.     unsigned int  x, y;
  788.     byte         *destline, *srcline;
  789.     byte         *destpixel, *srcpixel;
  790. !   byte          srcstartmask, srcmask;
  791.   
  792.     if (verbose) {
  793.       printf("  Merging bitmap image onto RGB image...");
  794. --- 134,140 ----
  795.     unsigned int  x, y;
  796.     byte         *destline, *srcline;
  797.     byte         *destpixel, *srcpixel;
  798. !   byte          srcmask;
  799.   
  800.     if (verbose) {
  801.       printf("  Merging bitmap image onto RGB image...");
  802. ***************
  803. *** 219,232 ****
  804.     for (x= 0; x < src->rgb.used; x++) {
  805.       for (y= 0; y < dest->rgb.used; y++)
  806.         if ((*(dest->rgb.red + y) == *(src->rgb.red + x)) &&
  807. !       (*(dest->rgb.red + y) == *(src->rgb.red + x)) &&
  808. !       (*(dest->rgb.red + y) == *(src->rgb.red + x))) {
  809.       *(index + x)= y;
  810.       break;
  811.         }
  812.       if (y == dest->rgb.used)
  813. !       printf("merge: warning: Can't map source pixel %d to destination\n",
  814. !          x);
  815.     }
  816.   
  817.     destlinelen= dest->width * dest->pixlen;
  818. --- 217,239 ----
  819.     for (x= 0; x < src->rgb.used; x++) {
  820.       for (y= 0; y < dest->rgb.used; y++)
  821.         if ((*(dest->rgb.red + y) == *(src->rgb.red + x)) &&
  822. !       (*(dest->rgb.green + y) == *(src->rgb.green + x)) &&
  823. !       (*(dest->rgb.blue + y) == *(src->rgb.blue + x))) {
  824.       *(index + x)= y;
  825.       break;
  826.         }
  827.       if (y == dest->rgb.used)
  828. !       if (y < dest->rgb.size) {
  829. !     *(dest->rgb.red + y)= *(src->rgb.red + x);
  830. !     *(dest->rgb.green + y)= *(src->rgb.green + x);
  831. !     *(dest->rgb.blue + y)= *(src->rgb.blue + x);
  832. !     *(index + x)= y;
  833. !     dest->rgb.used++;
  834. !       }
  835. !       else {
  836. !     printf("merge: warning: To few colors in destination colormap?!?\n");
  837. !     *(index + x)= 0;
  838. !       }
  839.     }
  840.   
  841.     destlinelen= dest->width * dest->pixlen;
  842. ***************
  843. *** 290,302 ****
  844.       cliph -= (dest->width - (aty + cliph));
  845.   
  846.     if (BITMAPP(dest) && (BITMAPP(src) || RGBP(src)))
  847. !     bitmapToBitmap(src, dest, atx, aty, clipw, cliph, verbose);
  848.     else {
  849.       mergeColors(dest, src, verbose);
  850.       if (RGBP(dest) && BITMAPP(src))
  851. !       bitmapToRGB(src, dest, atx, aty, clipw, cliph, verbose);
  852.       else if (RGBP(dest) && RGBP(src))
  853. !       RGBToRGB(src, dest, atx, aty, clipw, cliph, verbose);
  854.       else {
  855.         printf("merge: Can't merge these two types of images (sorry)\n");
  856.         exit(1);
  857. --- 297,312 ----
  858.       cliph -= (dest->width - (aty + cliph));
  859.   
  860.     if (BITMAPP(dest) && (BITMAPP(src) || RGBP(src)))
  861. !     bitmapToBitmap(src, dest, (unsigned int)atx, (unsigned int)aty,
  862. !            clipw, cliph, verbose);
  863.     else {
  864.       mergeColors(dest, src, verbose);
  865.       if (RGBP(dest) && BITMAPP(src))
  866. !       bitmapToRGB(src, dest, (unsigned int)atx, (unsigned int)aty,
  867. !           clipw, cliph, verbose);
  868.       else if (RGBP(dest) && RGBP(src))
  869. !       RGBToRGB(src, dest, (unsigned int)atx, (unsigned int)aty,
  870. !            clipw, cliph, verbose);
  871.       else {
  872.         printf("merge: Can't merge these two types of images (sorry)\n");
  873.         exit(1);
  874. diff -c xloadimage.02/misc.c xloadimage.03/misc.c
  875. *** xloadimage.02/misc.c    Sun Dec 31 16:03:12 1989
  876. --- xloadimage.03/misc.c    Wed Jan  3 15:32:37 1990
  877. ***************
  878. *** 4,11 ****
  879.    *
  880.    * jim frost 10.05.89
  881.    *
  882. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  883. !  * copyright information.
  884.    */
  885.   
  886.   #include "copyright.h"
  887. --- 4,11 ----
  888.    *
  889.    * jim frost 10.05.89
  890.    *
  891. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  892. !  * complete copyright information.
  893.    */
  894.   
  895.   #include "copyright.h"
  896. ***************
  897. *** 29,34 ****
  898. --- 29,35 ----
  899.     printf("  -quiet                - silence is golden\n");
  900.     printf("  -supported            - show supported image types\n");
  901.     printf("  -verbose              - whistle while you work\n");
  902. +   printf("  -version              - show version and patchlevel\n");
  903.     printf("  -view                 - view image in a window\n");
  904.     printf("Image_options:\n");
  905.     printf("  -at X,Y               - load image at location\n");
  906. ***************
  907. *** 69,75 ****
  908.     XColor        xcolor;
  909.     unsigned int  compressed= 0;
  910.   
  911. !   goodImage(image);
  912.   
  913.     /* clip the image if requested
  914.      */
  915. --- 70,76 ----
  916.     XColor        xcolor;
  917.     unsigned int  compressed= 0;
  918.   
  919. !   goodImage(image, "processImage");
  920.   
  921.     /* clip the image if requested
  922.      */
  923. ***************
  924. *** 149,154 ****
  925. --- 150,156 ----
  926.    * was issued.
  927.    */
  928.   
  929. + /* ARGSUSED */
  930.   int ioErrorHandler(disp)
  931.        Display *disp;
  932.   {
  933. diff -c xloadimage.02/new.c xloadimage.03/new.c
  934. *** xloadimage.02/new.c    Mon Nov  6 10:51:35 1989
  935. --- xloadimage.03/new.c    Wed Dec  6 14:56:08 1989
  936. ***************
  937. *** 49,55 ****
  938.     image= (Image *)lmalloc(sizeof(Image));
  939.     image->type= IBITMAP;
  940.     image->title= NULL;
  941. !   newRGBMapData(&(image->rgb), 2);
  942.     *(image->rgb.red)= *(image->rgb.green)= *(image->rgb.blue)= 65535;
  943.     *(image->rgb.red + 1)= *(image->rgb.green + 1)= *(image->rgb.blue + 1)= 0;
  944.     image->rgb.used= 2;
  945. --- 49,55 ----
  946.     image= (Image *)lmalloc(sizeof(Image));
  947.     image->type= IBITMAP;
  948.     image->title= NULL;
  949. !   newRGBMapData(&(image->rgb), (unsigned int)2);
  950.     *(image->rgb.red)= *(image->rgb.green)= *(image->rgb.blue)= 65535;
  951.     *(image->rgb.red + 1)= *(image->rgb.green + 1)= *(image->rgb.blue + 1)= 0;
  952.     image->rgb.used= 2;
  953. diff -c xloadimage.02/patchlevel xloadimage.03/patchlevel
  954. *** xloadimage.02/patchlevel    Sun Dec 31 16:03:17 1989
  955. --- xloadimage.03/patchlevel    Wed Jan  3 14:37:02 1990
  956. ***************
  957. *** 1 ****
  958. ! PATCHLEVEL 02
  959. --- 1,5 ----
  960. ! /* this defines the version and patchlevel of this version of xloadimage
  961. !  */
  962. ! #define VERSION    "1"
  963. ! #define PATCHLEVEL "03"
  964. diff -c xloadimage.02/path.c xloadimage.03/path.c
  965. *** xloadimage.02/path.c    Mon Nov  6 10:51:38 1989
  966. --- xloadimage.03/path.c    Wed Jan  3 15:33:01 1990
  967. ***************
  968. *** 4,11 ****
  969.    *
  970.    * jim frost 10.03.89
  971.    *
  972. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  973. !  * copyright information.
  974.    */
  975.   
  976.   #include "copyright.h"
  977. --- 4,11 ----
  978.    *
  979.    * jim frost 10.03.89
  980.    *
  981. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  982. !  * complete copyright information.
  983.    */
  984.   
  985.   #include "copyright.h"
  986. ***************
  987. *** 13,18 ****
  988. --- 13,19 ----
  989.   #include <sys/file.h>
  990.   #include <sys/types.h>
  991.   #include <sys/stat.h>
  992. + #include <unistd.h>
  993.   #include <pwd.h>
  994.   #include <errno.h>
  995.   
  996. ***************
  997. *** 62,73 ****
  998.   
  999.       if (!strncmp(tokenbuf, PathToken, strlen(PathToken))) {
  1000.         secnum= PATHSECTION;
  1001. !       if (sscanf(tokenbuf + strlen(PathToken), "%s", buf) == 0)
  1002.       continue;
  1003.       }
  1004.       else if (!strncmp(tokenbuf, ExtToken, strlen(ExtToken))) {
  1005.         secnum= EXTSECTION;
  1006. !       if (sscanf(tokenbuf + strlen(ExtToken), "%s", buf) == 0)
  1007.       continue;
  1008.       }
  1009.       else
  1010. --- 63,74 ----
  1011.   
  1012.       if (!strncmp(tokenbuf, PathToken, strlen(PathToken))) {
  1013.         secnum= PATHSECTION;
  1014. !       if (sscanf(tokenbuf + strlen(PathToken), "%s", buf) != 1)
  1015.       continue;
  1016.       }
  1017.       else if (!strncmp(tokenbuf, ExtToken, strlen(ExtToken))) {
  1018.         secnum= EXTSECTION;
  1019. !       if (sscanf(tokenbuf + strlen(ExtToken), "%s", buf) != 1)
  1020.       continue;
  1021.       }
  1022.       else
  1023. ***************
  1024. *** 110,124 ****
  1025.       return;
  1026.     havepaths= 1;
  1027.   
  1028. - #ifdef SYSPATHFILE
  1029. -   readPathsAndExts(SYSPATHFILE);
  1030. - #endif
  1031.     if (pw= getpwuid(getuid())) {
  1032.       sprintf(buf, "%s/.xloadimagerc", pw->pw_dir);
  1033. !     readPathsAndExts(buf);
  1034.     }
  1035.     else
  1036.       printf("Can't find your password file entry?!?\n");
  1037.   }
  1038.   
  1039.   /* find an image with paths and extensions from defaults files.  returns
  1040. --- 111,128 ----
  1041.       return;
  1042.     havepaths= 1;
  1043.   
  1044.     if (pw= getpwuid(getuid())) {
  1045.       sprintf(buf, "%s/.xloadimagerc", pw->pw_dir);
  1046. !     if (! access(buf, R_OK)) {
  1047. !       readPathsAndExts(buf);
  1048. !       return; /* don't read system file if user has one */
  1049. !     }
  1050.     }
  1051.     else
  1052.       printf("Can't find your password file entry?!?\n");
  1053. + #ifdef SYSPATHFILE
  1054. +   readPathsAndExts(SYSPATHFILE);
  1055. + #endif
  1056.   }
  1057.   
  1058.   /* find an image with paths and extensions from defaults files.  returns
  1059. diff -c xloadimage.02/pbm.c xloadimage.03/pbm.c
  1060. *** xloadimage.02/pbm.c    Mon Nov  6 10:51:39 1989
  1061. --- xloadimage.03/pbm.c    Wed Jan  3 15:34:04 1990
  1062. ***************
  1063. *** 3,8 ****
  1064. --- 3,11 ----
  1065.    * portable bit map (pbm) format images
  1066.    *
  1067.    * jim frost 09.27.89
  1068. +  *
  1069. +  * patched by W. David Higgins (wdh@mkt.csd.harris.com) to support
  1070. +  * raw-format PBM files.
  1071.    */
  1072.   
  1073.   #include "xloadimage.h"
  1074. ***************
  1075. *** 19,24 ****
  1076. --- 22,28 ----
  1077.   #define NOTPBM     1 /* not a pbm file */
  1078.   #define PBMNORMAL  2 /* pbm normal type file */
  1079.   #define PBMCOMPACT 3 /* pbm compacty type file */
  1080. + #define PBMRAWBITS 4 /* pbm raw bits type file */
  1081.   
  1082.   static void initializeTable()
  1083.   { unsigned int a;
  1084. ***************
  1085. *** 83,89 ****
  1086.   static int isPBM(zf, name, width, height, verbose)
  1087.        ZFILE        *zf;
  1088.        char         *name;
  1089. !      int          *width, *height;
  1090.        unsigned int  verbose;
  1091.   { unsigned char buf[4];
  1092.   
  1093. --- 87,93 ----
  1094.   static int isPBM(zf, name, width, height, verbose)
  1095.        ZFILE        *zf;
  1096.        char         *name;
  1097. !      unsigned int *width, *height;
  1098.        unsigned int  verbose;
  1099.   { unsigned char buf[4];
  1100.   
  1101. ***************
  1102. *** 99,104 ****
  1103. --- 103,115 ----
  1104.         printf("%s is a %dx%d PBM image\n", name, *width, *height);
  1105.       return(PBMNORMAL);
  1106.     }
  1107. +   if (memToVal(buf, 2) == memToVal("P4", 2)) {
  1108. +     if (((*width= pbmReadInt(zf)) < 0) || ((*height= pbmReadInt(zf)) < 0))
  1109. +       return(NOTPBM);
  1110. +     if (verbose)
  1111. +       printf("%s is a %dx%d RawBits PBM image\n", name, *width, *height);
  1112. +     return(PBMRAWBITS);
  1113. +   }
  1114.     if (memToVal(buf, 2) == 0x2a17) {
  1115.       if (zread(zf, buf, 4) != 4)
  1116.         return(NOTPBM);
  1117. ***************
  1118. *** 113,125 ****
  1119.   
  1120.   int pbmIdent(fullname, name)
  1121.        char *fullname, *name;
  1122. ! { ZFILE *zf;
  1123. !   int    width, height, ret;
  1124.   
  1125.     if (! (zf= zopen(fullname, name)))
  1126.       return(0);
  1127.   
  1128. !   ret= isPBM(zf, name, &width, &height, 1);
  1129.     zclose(zf);
  1130.     return(ret != NOTPBM);
  1131.   }
  1132. --- 124,136 ----
  1133.   
  1134.   int pbmIdent(fullname, name)
  1135.        char *fullname, *name;
  1136. ! { ZFILE        *zf;
  1137. !   unsigned int  width, height, ret;
  1138.   
  1139.     if (! (zf= zopen(fullname, name)))
  1140.       return(0);
  1141.   
  1142. !   ret= isPBM(zf, name, &width, &height, (unsigned int)1);
  1143.     zclose(zf);
  1144.     return(ret != NOTPBM);
  1145.   }
  1146. ***************
  1147. *** 130,136 ****
  1148.   { ZFILE        *zf;
  1149.     Image        *image;
  1150.     unsigned int  x, y;
  1151. !   int           width, height;
  1152.     unsigned int  linelen;
  1153.     byte          srcmask, destmask;
  1154.     byte         *destptr, *destline;
  1155. --- 141,147 ----
  1156.   { ZFILE        *zf;
  1157.     Image        *image;
  1158.     unsigned int  x, y;
  1159. !   unsigned int  width, height;
  1160.     unsigned int  linelen;
  1161.     byte          srcmask, destmask;
  1162.     byte         *destptr, *destline;
  1163. ***************
  1164. *** 185,190 ****
  1165. --- 196,241 ----
  1166.       }
  1167.       break;
  1168.   
  1169. +   case PBMRAWBITS:
  1170. +     image= newBitImage(width, height);
  1171. +     destline= image->data;
  1172. +     linelen= (width + 7) / 8;
  1173. +     numbytes= linelen * height;
  1174. +     srcmask= 0;        /* force initial read */
  1175. +     numread= 0;
  1176. +     for (y= 0; y < height; y++) {
  1177. +       destptr= destline;
  1178. +       destmask= 0x80;
  1179. +       if (srcmask != 0x80) {
  1180. +         srcmask= 0x80;
  1181. +     if ((numread < numbytes) && ((src= zgetc(zf)) == EOF)) {
  1182. +        printf("%s: Short image\n", fullname);
  1183. +        zclose(zf);
  1184. +        exit(1);
  1185. +     }
  1186. +     numread++;
  1187. +       }
  1188. +       for (x= 0; x < width; x++) {
  1189. +     if (src & srcmask)
  1190. +       *destptr |= destmask;
  1191. +     if (! (destmask >>= 1)) {
  1192. +       destmask= 0x80;
  1193. +       destptr++;
  1194. +     }
  1195. +     if (! (srcmask >>= 1)) {
  1196. +       srcmask= 0x80;
  1197. +       if ((numread < numbytes) && ((src= zgetc(zf)) == EOF)) {
  1198. +         printf("%s: Short image\n", fullname);
  1199. +         zclose(zf);
  1200. +         exit(1);
  1201. +       }
  1202. +       numread++;
  1203. +     }
  1204. +       }
  1205. +       destline += linelen;
  1206. +     }
  1207. +     break;
  1208. +  
  1209.     case PBMCOMPACT:
  1210.       image= newBitImage(width, height);
  1211.       destline= image->data;
  1212. diff -c xloadimage.02/reduce.c xloadimage.03/reduce.c
  1213. *** xloadimage.02/reduce.c    Mon Nov  6 10:51:40 1989
  1214. --- xloadimage.03/reduce.c    Wed Jan  3 15:34:29 1990
  1215. ***************
  1216. *** 4,11 ****
  1217.    *
  1218.    * jim frost 07.06.89
  1219.    *
  1220. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  1221. !  * copyright information.
  1222.    */
  1223.   
  1224.   #include "copyright.h"
  1225. --- 4,11 ----
  1226.    *
  1227.    * jim frost 07.06.89
  1228.    *
  1229. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  1230. !  * complete copyright information.
  1231.    */
  1232.   
  1233.   #include "copyright.h"
  1234. ***************
  1235. *** 46,51 ****
  1236. --- 46,52 ----
  1237.     unsigned long qdist, bdist;
  1238.   
  1239.     bdist= 0xffffffff;
  1240. +   bcolor= 0;
  1241.     for (qcolor= color + 1; qcolor < rgb->used; qcolor++)
  1242.       if ((qdist= colorDistance(rgb, color, qcolor)) && (qdist < bdist)) {
  1243.         bdist= qdist;
  1244. ***************
  1245. *** 56,63 ****
  1246.   }
  1247.   
  1248.   void reduceRGBMap(rgb, n, verbose)
  1249. !      RGBMap *rgb;
  1250. !      int     verbose;
  1251.   { unsigned int   numcolors;
  1252.     Pixel          a, b;
  1253.     Pixel          lowextreme, highextreme; /* intensity extremes */
  1254. --- 57,65 ----
  1255.   }
  1256.   
  1257.   void reduceRGBMap(rgb, n, verbose)
  1258. !      RGBMap       *rgb;
  1259. !      unsigned int  n;
  1260. !      unsigned int  verbose;
  1261.   { unsigned int   numcolors;
  1262.     Pixel          a, b;
  1263.     Pixel          lowextreme, highextreme; /* intensity extremes */
  1264. ***************
  1265. *** 169,177 ****
  1266.       *(best + a)= bestColor(rgb, a, dists + a);
  1267.     }
  1268.   
  1269. !   lfree(best);
  1270. !   lfree(dists);
  1271. !   lfree(same);
  1272.   
  1273.     if (verbose)
  1274.       printf("done\n");
  1275. --- 171,179 ----
  1276.       *(best + a)= bestColor(rgb, a, dists + a);
  1277.     }
  1278.   
  1279. !   lfree((byte *)best);
  1280. !   lfree((byte *)dists);
  1281. !   lfree((byte *)same);
  1282.   
  1283.     if (verbose)
  1284.       printf("done\n");
  1285. ***************
  1286. *** 182,188 ****
  1287.        unsigned int  n, verbose;
  1288.   { char buf[BUFSIZ];
  1289.   
  1290. !   goodImage(image);
  1291.     if (! RGBP(image)) /* we're AT&T */
  1292.       return;
  1293.     compress(image, verbose);
  1294. --- 184,190 ----
  1295.        unsigned int  n, verbose;
  1296.   { char buf[BUFSIZ];
  1297.   
  1298. !   goodImage(image, "reduce");
  1299.     if (! RGBP(image)) /* we're AT&T */
  1300.       return;
  1301.     compress(image, verbose);
  1302. ***************
  1303. *** 189,194 ****
  1304.     reduceRGBMap(&(image->rgb), n, verbose);
  1305.     compress(image, verbose);
  1306.     sprintf(buf, "%s (%d colors)", image->title, image->rgb.used);
  1307. !   lfree(image->title);
  1308.     image->title= dupString(buf);
  1309.   }
  1310. --- 191,197 ----
  1311.     reduceRGBMap(&(image->rgb), n, verbose);
  1312.     compress(image, verbose);
  1313.     sprintf(buf, "%s (%d colors)", image->title, image->rgb.used);
  1314. !   if (image->title)
  1315. !     lfree((byte *)image->title);
  1316.     image->title= dupString(buf);
  1317.   }
  1318. diff -c xloadimage.02/root.c xloadimage.03/root.c
  1319. *** xloadimage.02/root.c    Mon Nov  6 10:51:42 1989
  1320. --- xloadimage.03/root.c    Wed Jan  3 15:34:57 1990
  1321. ***************
  1322. *** 4,11 ****
  1323.    *
  1324.    * jim frost 10.03.89
  1325.    *
  1326. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  1327. !  * copyright information.
  1328.    */
  1329.   
  1330.   #include "copyright.h"
  1331. --- 4,11 ----
  1332.    *
  1333.    * jim frost 10.03.89
  1334.    *
  1335. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  1336. !  * complete copyright information.
  1337.    */
  1338.   
  1339.   #include "copyright.h"
  1340. ***************
  1341. *** 23,34 ****
  1342.     if (! sendImageToX(disp, scrn, DefaultVisual(disp, scrn), image,
  1343.                &pixmap, &xcmap, verbose))
  1344.       exit(1);
  1345.     XSetWindowBackgroundPixmap(disp, RootWindow(disp, scrn), pixmap);
  1346. -   XSetWindowColormap(disp, RootWindow(disp, scrn), xcmap);
  1347. -   if (install)
  1348. -     XInstallColormap(disp, scrn, xcmap);
  1349.     XClearWindow(disp, RootWindow(disp, scrn));
  1350. -   XFreeColormap(disp, xcmap);
  1351.     XFreePixmap(disp, pixmap);
  1352.     XSetCloseDownMode(disp, RetainPermanent);
  1353.   }
  1354. --- 23,40 ----
  1355.     if (! sendImageToX(disp, scrn, DefaultVisual(disp, scrn), image,
  1356.                &pixmap, &xcmap, verbose))
  1357.       exit(1);
  1358. +   /* changing the root colormap is A Bad Thing, so deny it.
  1359. +    */
  1360. +   if (xcmap != DefaultColormap(disp, scrn)) {
  1361. +     printf("Loading image onto root would change default colormap (sorry)\n");
  1362. +     XFreePixmap(disp, pixmap);
  1363. +     exit(1);
  1364. +   }
  1365.     XSetWindowBackgroundPixmap(disp, RootWindow(disp, scrn), pixmap);
  1366.     XClearWindow(disp, RootWindow(disp, scrn));
  1367.     XFreePixmap(disp, pixmap);
  1368.     XSetCloseDownMode(disp, RetainPermanent);
  1369.   }
  1370. diff -c xloadimage.02/send.c xloadimage.03/send.c
  1371. *** xloadimage.02/send.c    Mon Nov  6 11:00:04 1989
  1372. --- xloadimage.03/send.c    Wed Jan  3 15:35:19 1990
  1373. ***************
  1374. *** 4,11 ****
  1375.    *
  1376.    * jim frost 10.02.89
  1377.    *
  1378. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  1379. !  * copyright information.
  1380.    */
  1381.   
  1382.   #include "copyright.h"
  1383. --- 4,11 ----
  1384.    *
  1385.    * jim frost 10.02.89
  1386.    *
  1387. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  1388. !  * complete copyright information.
  1389.    */
  1390.   
  1391.   #include "copyright.h"
  1392. ***************
  1393. *** 20,27 ****
  1394.        Colormap     *cmap;
  1395.        unsigned int  verbose;
  1396.   { Pixel        *index;
  1397. !   unsigned int  a, newmap, x, y;
  1398. !   byte         *pixptr;
  1399.     XColor        xcolor;
  1400.     XGCValues     gcv;
  1401.     GC            gc;
  1402. --- 20,28 ----
  1403.        Colormap     *cmap;
  1404.        unsigned int  verbose;
  1405.   { Pixel        *index;
  1406. !   unsigned int  a, b, newmap, x, y, linelen, ddepth;
  1407. !   unsigned long plane;
  1408. !   byte         *pixptr, *destline, *destptr, *bitplane, destmask;
  1409.     XColor        xcolor;
  1410.     XGCValues     gcv;
  1411.     GC            gc;
  1412. ***************
  1413. *** 49,103 ****
  1414.     if (visual == DefaultVisual(disp, scrn)) {
  1415.       *cmap= DefaultColormap(disp, scrn);
  1416.       newmap= 0;
  1417. -   }
  1418. -   else {
  1419. -     if ((visual->class == PseudoColor) || (visual->class == GrayScale))
  1420. -       *cmap= XCreateColormap(disp, scrn, AllocNone);
  1421. -     else
  1422. -       *cmap= XCreateColormap(disp, scrn, AllocAll);
  1423. -     newmap= 1;
  1424. -   }
  1425.   
  1426. !   /* here's where we have fun; we try to build a reasonable colormap from
  1427. !    * whatever X will give us.  ugh.  blech.  gag.  puke.  barf.
  1428. !    */
  1429.   
  1430. -   if ((visual->class == PseudoColor) || (visual->class == GrayScale)) {
  1431.       for (a= 0; a < image->rgb.used; a++) {
  1432. !       if (! XAllocColorCells(disp, *cmap, False, NULL, 0, index + a, 1))
  1433. !     if (newmap)
  1434. !       break;
  1435.       else {
  1436. !       *cmap= XCopyColormapAndFree(disp, *cmap);
  1437.         newmap= 1;
  1438. !       a--;
  1439.       }
  1440.       }
  1441.       if (a < image->rgb.used)     /* can't get enough colors, so reduce */
  1442.         reduce(image, a, verbose); /* the colormap to fit what we have */
  1443. !     for (a= 0; a < image->rgb.used; a++) {
  1444. !       xcolor.pixel= *(index + a);
  1445. !       xcolor.red= *(image->rgb.red + a);
  1446. !       xcolor.green= *(image->rgb.green + a);
  1447. !       xcolor.blue= *(image->rgb.blue + a);
  1448.         XStoreColor(disp, *cmap, &xcolor);
  1449.       }
  1450.     }
  1451. -   else if ((visual->class == StaticColor) || (visual->class == StaticGray)) {
  1452. -     for (a= 0; a < image->rgb.used; a++) {
  1453. -       xcolor.red= *(image->rgb.red + a);
  1454. -       xcolor.green= *(image->rgb.green + a);
  1455. -       xcolor.blue= *(image->rgb.blue + a);
  1456. -       if (! XAllocColor(disp, *cmap, &xcolor)) {
  1457. -     printf("sendImageToX: XAllocColor failed on StaticGrey visual\n");
  1458. -     return(0);
  1459. -       }
  1460. -       *(index + a)= xcolor.pixel;
  1461. -     }
  1462. -   }
  1463.   
  1464.     *pixmap= XCreatePixmap(disp, RootWindow(disp, scrn), image->width,
  1465. !              image->height, DefaultDepth(disp, scrn));
  1466.   
  1467.     /* blast the image across
  1468.      */
  1469. --- 50,113 ----
  1470.     if (visual == DefaultVisual(disp, scrn)) {
  1471.       *cmap= DefaultColormap(disp, scrn);
  1472.       newmap= 0;
  1473.   
  1474. !     /* allocate colors shareable (if we can)
  1475. !      */
  1476.   
  1477.       for (a= 0; a < image->rgb.used; a++) {
  1478. !       xcolor.red= *(image->rgb.red + a);
  1479. !       xcolor.green= *(image->rgb.green + a);
  1480. !       xcolor.blue= *(image->rgb.blue + a);
  1481. !       if (! XAllocColor(disp, *cmap, &xcolor))
  1482. !     if ((visual->class == StaticColor) || (visual->class == StaticGray)) {
  1483. !       printf("sendImageToX: XAllocColor failed on a static visual\n");
  1484. !       return(0);
  1485. !     }
  1486.       else {
  1487. !       /* we can't allocate the colors shareable so free all the colors
  1488. !        * we had allocated and create a private colormap
  1489. !        */
  1490. !       for (b= 0; b < a; b++)
  1491. !         XFreeColors(disp, *cmap, index + b, 1, 0);
  1492. !       *cmap= XCreateColormap(disp, RootWindow(disp, scrn), visual,
  1493. !                  AllocNone);
  1494.         newmap= 1;
  1495. !       break;
  1496.       }
  1497. +       *(index + a)= xcolor.pixel;
  1498.       }
  1499. +   }
  1500. +   else {
  1501. +     if ((visual->class == PseudoColor) || (visual->class == GrayScale)) {
  1502. +       *cmap= XCreateColormap(disp, RootWindow(disp, scrn), AllocNone);
  1503. +     }
  1504. +     else
  1505. +       *cmap= XCreateColormap(disp, RootWindow(disp, scrn), AllocAll);
  1506. +     newmap= 1;
  1507. +   }
  1508. +   if (newmap) {
  1509. +     for (a= 0; a < image->rgb.used; a++) /* count entries we got */
  1510. +       if (! XAllocColorCells(disp, *cmap, False, NULL, 0, index + a, 1))
  1511. +     break;
  1512.       if (a < image->rgb.used)     /* can't get enough colors, so reduce */
  1513.         reduce(image, a, verbose); /* the colormap to fit what we have */
  1514. !     for (b= 0; b < a; b++) {
  1515. !       xcolor.pixel= *(index + b);
  1516. !       xcolor.red= *(image->rgb.red + b);
  1517. !       xcolor.green= *(image->rgb.green + b);
  1518. !       xcolor.blue= *(image->rgb.blue + b);
  1519.         XStoreColor(disp, *cmap, &xcolor);
  1520.       }
  1521.     }
  1522.   
  1523. +   ddepth= DefaultDepth(disp, scrn);
  1524.     *pixmap= XCreatePixmap(disp, RootWindow(disp, scrn), image->width,
  1525. !              image->height, ddepth);
  1526.   
  1527.     /* blast the image across
  1528.      */
  1529. ***************
  1530. *** 120,130 ****
  1531.   
  1532.     case IRGB:
  1533.   
  1534. !     /* modify pixel values to fit the colormap
  1535.        */
  1536.   
  1537.       if (verbose) {
  1538. !       printf("  Modifying image to conform to X colormap...");
  1539.         fflush(stdout);
  1540.       }
  1541.       pixptr= image->data;
  1542. --- 130,140 ----
  1543.   
  1544.     case IRGB:
  1545.   
  1546. !     /* modify image data to match colormap and pack pixels if necessary
  1547.        */
  1548.   
  1549.       if (verbose) {
  1550. !       printf("  Building XImage...");
  1551.         fflush(stdout);
  1552.       }
  1553.       pixptr= image->data;
  1554. ***************
  1555. *** 134,145 ****
  1556.            pixptr, image->pixlen);
  1557.       pixptr += image->pixlen;
  1558.         }
  1559.       if (verbose)
  1560.         printf("done\n");
  1561.   
  1562.       gcv.function= GXcopy;
  1563.       gc= XCreateGC(disp, *pixmap, GCFunction, &gcv);
  1564. !     ximage= XCreateImage(disp, visual, image->depth, ZPixmap, 0, image->data,
  1565.                image->width, image->height, 8, 0);
  1566.       ximage->byte_order= MSBFirst; /* trust me, i know what i'm talking about */
  1567.   
  1568. --- 144,208 ----
  1569.            pixptr, image->pixlen);
  1570.       pixptr += image->pixlen;
  1571.         }
  1572.       if (verbose)
  1573.         printf("done\n");
  1574.   
  1575. +     /* if the destination depth is not a multiple of 8, then we send each
  1576. +      * plane as a bitmap because otherwise we would have to pack the pixel
  1577. +      * data and the XImage format is pretty vague about how that should
  1578. +      * be done.  this is not as fast as it would be if it were packed but
  1579. +      * it should be a lot more portable and only slightly slower.
  1580. +      */
  1581. +     if (ddepth % 8) {
  1582. +       gcv.function= GXcopy;
  1583. +       gcv.background= 0;
  1584. +       gc= XCreateGC(disp, *pixmap, GCFunction | GCBackground, &gcv);
  1585. +       linelen= (image->width / 8) + (image->width % 8 ? 1 : 0);
  1586. +       bitplane= lmalloc(image->height * linelen);
  1587. +       ximage= XCreateImage(disp, visual, 1, XYBitmap, 0, bitplane,
  1588. +                image->width, image->height, 8, 0);
  1589. +       ximage->bitmap_bit_order= MSBFirst;
  1590. +       ximage->byte_order= MSBFirst;
  1591. +       for (plane= 1 << (ddepth - 1); plane; plane >>= 1) {
  1592. +     pixptr= image->data;
  1593. +     destline= bitplane;
  1594. +     for (y= 0; y < image->height; y++) {
  1595. +       destmask= 0x80;
  1596. +       destptr= destline;
  1597. +       for (x= 0; x < image->width; x++) {
  1598. +         if (*pixptr & plane)
  1599. +           *destptr |= destmask;
  1600. +         else
  1601. +           *destptr &= ~destmask;
  1602. +         if (!(destmask >>= 1)) {
  1603. +           destmask= 0x80;
  1604. +           destptr++;
  1605. +         }
  1606. +         pixptr += image->pixlen;
  1607. +       }
  1608. +       destline += linelen;
  1609. +     }
  1610. +     XSetForeground(disp, gc, plane);
  1611. +     XSetPlaneMask(disp, gc, plane);
  1612. +     XPutImage(disp, *pixmap, gc, ximage, 0, 0, 0, 0,
  1613. +           image->width, image->height);
  1614. +       }
  1615. +       ximage->data= NULL;
  1616. +       XDestroyImage(ximage);
  1617. +       lfree(bitplane);
  1618. +       break;
  1619. +     }
  1620. +     /* send image across in one whack
  1621. +      */
  1622.       gcv.function= GXcopy;
  1623.       gc= XCreateGC(disp, *pixmap, GCFunction, &gcv);
  1624. !     ximage= XCreateImage(disp, visual, ddepth, ZPixmap, 0, image->data,
  1625.                image->width, image->height, 8, 0);
  1626.       ximage->byte_order= MSBFirst; /* trust me, i know what i'm talking about */
  1627.   
  1628. ***************
  1629. *** 154,159 ****
  1630.       printf("sendImageToX: bad image type\n");
  1631.       return(0);
  1632.     }
  1633. !   lfree(index);
  1634.     return(1);
  1635.   }
  1636. --- 217,222 ----
  1637.       printf("sendImageToX: bad image type\n");
  1638.       return(0);
  1639.     }
  1640. !   lfree((byte *)index);
  1641.     return(1);
  1642.   }
  1643. diff -c xloadimage.02/value.c xloadimage.03/value.c
  1644. *** xloadimage.02/value.c    Sun Dec 31 16:03:13 1989
  1645. --- xloadimage.03/value.c    Wed Dec  6 15:20:32 1989
  1646. ***************
  1647. *** 14,21 ****
  1648.   #include "image.h"
  1649.   
  1650.   unsigned long memToVal(p, len)
  1651. !      byte *p;
  1652. !      int   len;
  1653.   { unsigned int  a;
  1654.     unsigned long i;
  1655.   
  1656. --- 14,21 ----
  1657.   #include "image.h"
  1658.   
  1659.   unsigned long memToVal(p, len)
  1660. !      byte         *p;
  1661. !      unsigned int  len;
  1662.   { unsigned int  a;
  1663.     unsigned long i;
  1664.   
  1665. ***************
  1666. *** 55,62 ****
  1667.        byte          *p;
  1668.        unsigned long  val;
  1669.        unsigned int   len;
  1670. ! { int a;
  1671.     while (len--) {
  1672.       *(p++)= val & 0xff;
  1673.       val >>= 8;
  1674. --- 55,61 ----
  1675.        byte          *p;
  1676.        unsigned long  val;
  1677.        unsigned int   len;
  1678. ! {
  1679.     while (len--) {
  1680.       *(p++)= val & 0xff;
  1681.       val >>= 8;
  1682. diff -c xloadimage.02/window.c xloadimage.03/window.c
  1683. *** xloadimage.02/window.c    Mon Nov  6 11:00:11 1989
  1684. --- xloadimage.03/window.c    Wed Jan  3 15:35:42 1990
  1685. ***************
  1686. *** 4,11 ****
  1687.    *
  1688.    * jim frost 10.03.89
  1689.    *
  1690. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  1691. !  * copyright information.
  1692.    */
  1693.   
  1694.   #include "copyright.h"
  1695. --- 4,11 ----
  1696.    *
  1697.    * jim frost 10.03.89
  1698.    *
  1699. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  1700. !  * complete copyright information.
  1701.    */
  1702.   
  1703.   #include "copyright.h"
  1704. ***************
  1705. *** 20,30 ****
  1706.        Cursor       *cursor;
  1707.   { XSetWindowAttributes swa;
  1708.   
  1709. !   if ((ww == iw) && (wh == ih))
  1710.       swa.cursor= XCreateFontCursor(disp, XC_icon);
  1711. !   else if ((ww < iw) && (wh == ih))
  1712.       swa.cursor= XCreateFontCursor(disp, XC_sb_h_double_arrow);
  1713. !   else if ((ww == iw) && (wh < ih))
  1714.       swa.cursor= XCreateFontCursor(disp, XC_sb_v_double_arrow);
  1715.     else
  1716.       swa.cursor= XCreateFontCursor(disp, XC_fleur);
  1717. --- 20,30 ----
  1718.        Cursor       *cursor;
  1719.   { XSetWindowAttributes swa;
  1720.   
  1721. !   if ((ww >= iw) && (wh >= ih))
  1722.       swa.cursor= XCreateFontCursor(disp, XC_icon);
  1723. !   else if ((ww < iw) && (wh >= ih))
  1724.       swa.cursor= XCreateFontCursor(disp, XC_sb_h_double_arrow);
  1725. !   else if ((ww >= iw) && (wh < ih))
  1726.       swa.cursor= XCreateFontCursor(disp, XC_sb_v_double_arrow);
  1727.     else
  1728.       swa.cursor= XCreateFontCursor(disp, XC_fleur);
  1729. ***************
  1730. *** 117,123 ****
  1731.     XSetNormalHints(disp, window, &sh);
  1732.   
  1733.     gcv.function= GXcopy;
  1734. !   gc= XCreateGC(disp, window, GCFunction, &gcv);
  1735.     XMapWindow(disp, window);
  1736.     pixx= pixy= 0;
  1737.     lastx= lasty= -1;
  1738. --- 117,124 ----
  1739.     XSetNormalHints(disp, window, &sh);
  1740.   
  1741.     gcv.function= GXcopy;
  1742. !   gcv.foreground= 0;
  1743. !   gc= XCreateGC(disp, window, GCFunction | GCForeground, &gcv);
  1744.     XMapWindow(disp, window);
  1745.     pixx= pixy= 0;
  1746.     lastx= lasty= -1;
  1747. ***************
  1748. *** 133,147 ****
  1749.       lasty= event.button.y;
  1750.       break;
  1751.         }
  1752. - #ifdef NUKE_ME
  1753. -       XDestroyWindow(disp, window);
  1754. -       XFreeCursor(disp, swa.cursor);
  1755. -       XFreePixmap(disp, pixmap);
  1756. -       XFreeColormap(disp, xcmap);
  1757. -       return;
  1758. - #else
  1759.         break;
  1760. - #endif
  1761.   
  1762.       case KeyPress: {
  1763.         char buf[128];
  1764. --- 134,140 ----
  1765. ***************
  1766. *** 153,159 ****
  1767.           XDestroyWindow(disp, window);
  1768.           XFreeCursor(disp, swa.cursor);
  1769.           XFreePixmap(disp, pixmap);
  1770. !         XFreeColormap(disp, xcmap);
  1771.           return;
  1772.         }
  1773.       }
  1774. --- 146,153 ----
  1775.           XDestroyWindow(disp, window);
  1776.           XFreeCursor(disp, swa.cursor);
  1777.           XFreePixmap(disp, pixmap);
  1778. !     if (xcmap != DefaultColormap(disp, scrn))
  1779. !           XFreeColormap(disp, xcmap);
  1780.           return;
  1781.         }
  1782.       }
  1783. ***************
  1784. *** 160,165 ****
  1785. --- 154,161 ----
  1786.         break;
  1787.   
  1788.       case MotionNotify:
  1789. +       if ((image->width <= winwidth) && (image->height <= winheight))
  1790. +     break; /* we're AT&T */
  1791.         mousex= event.button.x;
  1792.         mousey= event.button.y;
  1793.         while (XCheckTypedEvent(disp, MotionNotify, &event) == True) {
  1794. ***************
  1795. *** 170,209 ****
  1796.         pixy += lasty - mousey;
  1797.         lastx= mousex;
  1798.         lasty= mousey;
  1799. !       if (pixx < 0)
  1800. !     pixx= 0;
  1801. !       if (pixy < 0)
  1802. !     pixy= 0;
  1803. !       if (pixx + winwidth > image->width)
  1804. !     pixx= image->width - winwidth;
  1805. !       if (pixy + winheight > image->height)
  1806. !     pixy= image->height - winheight;
  1807.         XCopyArea(disp, pixmap, window, gc,
  1808.           pixx, pixy, winwidth, winheight, 0, 0);
  1809.         break;
  1810.   
  1811.       case ConfigureNotify:
  1812.   
  1813. -       /* if we got resized too big, fix it.  it's a stupid window manager.
  1814. -        */
  1815. -       if ((event.configure.width > image->width) ||
  1816. -       (event.configure.height > image->height)) {
  1817. -     if (event.configure.width > image->width)
  1818. -       winwidth= image->width;
  1819. -     else
  1820. -       winwidth= event.configure.width;
  1821. -     if (event.configure.height > image->height)
  1822. -       winheight= image->height;
  1823. -     else
  1824. -       winheight= event.configure.height;
  1825. -     XResizeWindow(disp, window, winwidth, winheight);
  1826. -       }
  1827. -       else {
  1828. -     winwidth= event.configure.width;
  1829. -     winheight= event.configure.height;
  1830. -       }
  1831.         /* configure the cursor to indicate which directions we can drag
  1832.          */
  1833.   
  1834. --- 166,191 ----
  1835.         pixy += lasty - mousey;
  1836.         lastx= mousex;
  1837.         lasty= mousey;
  1838. !       if (image->width > winwidth) {
  1839. !     if (pixx < 0)
  1840. !       pixx= 0;
  1841. !     if (pixx + winwidth > image->width)
  1842. !       pixx= image->width - winwidth;
  1843. !       }
  1844. !       if (image->height > winheight) {
  1845. !     if (pixy < 0)
  1846. !       pixy= 0;
  1847. !     if (pixy + winheight > image->height)
  1848. !       pixy= image->height - winheight;
  1849. !       }
  1850.         XCopyArea(disp, pixmap, window, gc,
  1851.           pixx, pixy, winwidth, winheight, 0, 0);
  1852.         break;
  1853.   
  1854.       case ConfigureNotify:
  1855. +       winwidth= event.configure.width;
  1856. +       winheight= event.configure.height;
  1857.   
  1858.         /* configure the cursor to indicate which directions we can drag
  1859.          */
  1860.   
  1861. ***************
  1862. *** 211,216 ****
  1863. --- 193,202 ----
  1864.       pixx= image->width - winwidth;
  1865.         if (pixy + winheight > image->height)
  1866.       pixy= image->height - winheight;
  1867. +       if (winwidth > image->width)
  1868. +     pixx= 0;
  1869. +       if (winheight > image->height)
  1870. +     pixy= 0;
  1871.         setCursor(disp, window, image->width, image->height,
  1872.           winwidth, winheight, &(swa.cursor));
  1873.   
  1874. ***************
  1875. *** 224,230 ****
  1876.       case DestroyNotify:
  1877.         XFreeCursor(disp, swa.cursor);
  1878.         XFreePixmap(disp, pixmap);
  1879. !       XFreeColormap(disp, xcmap);
  1880.         return;
  1881.   
  1882.       case Expose:
  1883. --- 210,217 ----
  1884.       case DestroyNotify:
  1885.         XFreeCursor(disp, swa.cursor);
  1886.         XFreePixmap(disp, pixmap);
  1887. !       if (xcmap != DefaultColormap(disp, scrn))
  1888. !     XFreeColormap(disp, xcmap);
  1889.         return;
  1890.   
  1891.       case Expose:
  1892. diff -c xloadimage.02/xbitmap.c xloadimage.03/xbitmap.c
  1893. *** xloadimage.02/xbitmap.c    Mon Nov  6 11:00:08 1989
  1894. --- xloadimage.03/xbitmap.c    Wed Dec  6 15:07:38 1989
  1895. ***************
  1896. *** 241,247 ****
  1897.        char         *fullname, *name;
  1898.   { Image *image;
  1899.   
  1900. !   if (image= xbitmapLoad(fullname, name, 1)) {
  1901.       freeImage(image);
  1902.       return(1);
  1903.     }
  1904. --- 241,247 ----
  1905.        char         *fullname, *name;
  1906.   { Image *image;
  1907.   
  1908. !   if (image= xbitmapLoad(fullname, name, (unsigned int)1)) {
  1909.       freeImage(image);
  1910.       return(1);
  1911.     }
  1912. diff -c xloadimage.02/xloadimage.c xloadimage.03/xloadimage.c
  1913. *** xloadimage.02/xloadimage.c    Sun Dec 31 16:03:14 1989
  1914. --- xloadimage.03/xloadimage.c    Wed Jan  3 15:36:19 1990
  1915. ***************
  1916. *** 4,15 ****
  1917.    *
  1918.    * jim frost 09.27.89
  1919.    *
  1920. !  * Copyright 1989 Jim Frost.  See included file "copyright.h" for complete
  1921. !  * copyright information.
  1922.    */
  1923.   
  1924.   #include "copyright.h"
  1925.   #include "xloadimage.h"
  1926.   
  1927.   /* options array and definitions
  1928.    */
  1929. --- 4,16 ----
  1930.    *
  1931.    * jim frost 09.27.89
  1932.    *
  1933. !  * Copyright 1989, 1990 Jim Frost.  See included file "copyright.h" for
  1934. !  * complete copyright information.
  1935.    */
  1936.   
  1937.   #include "copyright.h"
  1938.   #include "xloadimage.h"
  1939. + #include "patchlevel"
  1940.   
  1941.   /* options array and definitions
  1942.    */
  1943. ***************
  1944. *** 27,32 ****
  1945. --- 28,34 ----
  1946.     "quiet",
  1947.     "supported",
  1948.     "verbose",
  1949. +   "version",
  1950.     "view",
  1951.   
  1952.     "at", /* image options */
  1953. ***************
  1954. *** 57,77 ****
  1955.   #define QUIET     9
  1956.   #define SUPPORTED 10
  1957.   #define VERBOSE   11
  1958. ! #define VIEW      12
  1959.   
  1960. ! #define AT         13
  1961. ! #define BACKGROUND 14
  1962. ! #define BRIGHT     15
  1963. ! #define CENTER     16
  1964. ! #define CLIP       17
  1965. ! #define COLORS     18
  1966. ! #define DITHER     19
  1967. ! #define FOREGROUND 20
  1968. ! #define HALFTONE   21
  1969. ! #define NAME       22
  1970. ! #define XZOOM      23
  1971. ! #define YZOOM      24
  1972. ! #define ZOOM       25
  1973.   
  1974.   /* if an image loader needs to have our display and screen, it will get
  1975.    * them from here.  this is done to keep most of the image routines
  1976. --- 59,80 ----
  1977.   #define QUIET     9
  1978.   #define SUPPORTED 10
  1979.   #define VERBOSE   11
  1980. ! #define VER_NUM   12
  1981. ! #define VIEW      13
  1982.   
  1983. ! #define AT         14
  1984. ! #define BACKGROUND 15
  1985. ! #define BRIGHT     16
  1986. ! #define CENTER     17
  1987. ! #define CLIP       18
  1988. ! #define COLORS     19
  1989. ! #define DITHER     20
  1990. ! #define FOREGROUND 21
  1991. ! #define HALFTONE   22
  1992. ! #define NAME       23
  1993. ! #define XZOOM      24
  1994. ! #define YZOOM      25
  1995. ! #define ZOOM       26
  1996.   
  1997.   /* if an image loader needs to have our display and screen, it will get
  1998.    * them from here.  this is done to keep most of the image routines
  1999. ***************
  2000. *** 129,134 ****
  2001. --- 132,149 ----
  2002.     winx= winy= winwidth= winheight= 0;
  2003.   
  2004.     imagecount= 0;
  2005. +   for (a= 0; a < MAXIMAGES; a++) {
  2006. +     images[a].name= NULL;
  2007. +     images[a].atx= images[a].aty= 0;
  2008. +     images[a].bright= 0;
  2009. +     images[a].center= 0;
  2010. +     images[a].clipx= images[a].clipy= 0;
  2011. +     images[a].clipw= images[a].cliph= 0;
  2012. +     images[a].dither= 0;
  2013. +     images[a].colors= 0;
  2014. +     images[a].fg= images[a].bg= NULL;
  2015. +     images[a].xzoom= images[a].yzoom= 0;
  2016. +   }
  2017.     for (a= 1; a < argc; a++) {
  2018.       switch (optionNumber(argv[a], Options)) {
  2019.       case OPT_BADOPT:
  2020. ***************
  2021. *** 199,206 ****
  2022. --- 214,227 ----
  2023.         verbose= 1;
  2024.         break;
  2025.   
  2026. +     case VER_NUM:
  2027. +       printf("Xloadimage version %s patchlevel %s by Jim Frost\n",
  2028. +          VERSION, PATCHLEVEL);
  2029. +       break;
  2030.       case VIEW:
  2031.         onroot= 0;
  2032. +       break;
  2033.   
  2034.       /* process options local to an image
  2035.        */
  2036. ***************
  2037. *** 330,336 ****
  2038.         *dispimage->rgb.green= xcolor.green;
  2039.         *dispimage->rgb.blue= xcolor.blue;
  2040.       }
  2041. !     fill(dispimage, 0, 0, winwidth, winheight, 0, verbose);
  2042.     }
  2043.   
  2044.     /* load in each named image
  2045. --- 351,357 ----
  2046.         *dispimage->rgb.green= xcolor.green;
  2047.         *dispimage->rgb.blue= xcolor.blue;
  2048.       }
  2049. !     fill(dispimage, 0, 0, winwidth, winheight, 0);
  2050.     }
  2051.   
  2052.     /* load in each named image
  2053. diff -c xloadimage.02/xloadimage.h xloadimage.03/xloadimage.h
  2054. *** xloadimage.02/xloadimage.h    Mon Nov  6 10:51:58 1989
  2055. --- xloadimage.03/xloadimage.h    Wed Dec  6 15:08:47 1989
  2056. ***************
  2057. *** 38,43 ****
  2058. --- 38,45 ----
  2059.   /* function declarations
  2060.    */
  2061.   
  2062. + void supportedImageTypes(); /* imagetypes.c */
  2063.   ZFILE *zopen(); /* io.c */
  2064.   int    zread();
  2065.   int    zgetc();
  2066. diff -c xloadimage.02/xloadimage.man xloadimage.03/xloadimage.man
  2067. *** xloadimage.02/xloadimage.man    Sun Dec 31 16:03:15 1989
  2068. --- xloadimage.03/xloadimage.man    Wed Jan  3 15:51:00 1990
  2069. ***************
  2070. *** 1,4 ****
  2071. ! .TH XLOADIMAGE 1 "7 October 1989"
  2072.   .SH NAME
  2073.   xloadimage, xsetbg, xview \- load images into an X11 window or onto
  2074.   the root window
  2075. --- 1,4 ----
  2076. ! .TH XLOADIMAGE 1 "13 December 1989"
  2077.   .SH NAME
  2078.   xloadimage, xsetbg, xview \- load images into an X11 window or onto
  2079.   the root window
  2080. ***************
  2081. *** 7,14 ****
  2082.   .SH DESCRIPTION
  2083.   \fIXloadimage\fR displays images in an X11 window or loads them onto
  2084.   the root window.  See the \fIIMAGE TYPES\fR section below for
  2085. ! supported image types.  Compressed images will automatically be
  2086. ! uncompressed.
  2087.   .PP
  2088.   If the destination display cannot support the number of colors in the
  2089.   image, the image will be dithered (monochrome destination) or have its
  2090. --- 7,13 ----
  2091.   .SH DESCRIPTION
  2092.   \fIXloadimage\fR displays images in an X11 window or loads them onto
  2093.   the root window.  See the \fIIMAGE TYPES\fR section below for
  2094. ! supported image types.
  2095.   .PP
  2096.   If the destination display cannot support the number of colors in the
  2097.   image, the image will be dithered (monochrome destination) or have its
  2098. ***************
  2099. *** 19,25 ****
  2100.   single image.  The \fI-at\fR and \fI-center\fR options control where
  2101.   subsequent images will be loaded onto the initial image.  Any
  2102.   combination of color image depths and/or monochrome images may be
  2103. ! loaded at one time.
  2104.   .PP
  2105.   A variety of image manipulations can be specified, including
  2106.   brightening, clipping, dithering, depth-reduction, and zooming.  Most
  2107. --- 18,26 ----
  2108.   single image.  The \fI-at\fR and \fI-center\fR options control where
  2109.   subsequent images will be loaded onto the initial image.  Any
  2110.   combination of color image depths and/or monochrome images may be
  2111. ! loaded at one time.  If merging two color images would overload the
  2112. ! number of available colormap entries, the number of colors shared
  2113. ! between the images will be automatically reduced to fit.
  2114.   .PP
  2115.   A variety of image manipulations can be specified, including
  2116.   brightening, clipping, dithering, depth-reduction, and zooming.  Most
  2117. ***************
  2118. *** 27,38 ****
  2119.   for above accuracy.
  2120.   .PP
  2121.   If you are viewing a large image in a window, the initial window will
  2122. ! be at most 90% of the size of the display.  You may move the image
  2123. ! around in the window by dragging with the first mouse button.  The
  2124. ! cursor will indicate which directions you may drag, if any.  You may
  2125. ! exit the window by typing 'q' or 'Q' when the keyboard focus is on the
  2126. ! window.
  2127.   .PP
  2128.   \fIXsetbg\fR is equivalent to \fIxloadimage -onroot -quiet\fR and
  2129.   \fIxview\fR is equivalent to \fIxloadimage -view -verbose\fR.
  2130.   .SH GLOBAL OPTIONS
  2131. --- 28,44 ----
  2132.   for above accuracy.
  2133.   .PP
  2134.   If you are viewing a large image in a window, the initial window will
  2135. ! be at most 90% of the size of the display (unless the window manager
  2136. ! does not correctly handle window size requests).  You may move the
  2137. ! image around in the window by dragging with the first mouse button.
  2138. ! The cursor will indicate which directions you may drag, if any.  You
  2139. ! may exit the window by typing 'q' or 'Q' when the keyboard focus is on
  2140. ! the window.
  2141.   .PP
  2142. + A wide variety of common image manipulations can be done by mixing and
  2143. + matching the available options.  See the section entitled \fIHINTS FOR
  2144. + GOOD IMAGE DISPLAYS\fR for some ideas.
  2145. + .PP
  2146.   \fIXsetbg\fR is equivalent to \fIxloadimage -onroot -quiet\fR and
  2147.   \fIxview\fR is equivalent to \fIxloadimage -view -verbose\fR.
  2148.   .SH GLOBAL OPTIONS
  2149. ***************
  2150. *** 43,52 ****
  2151.   This sets the background portion of the window which is not covered by
  2152.   any images to be \fIcolor\fR.
  2153.   .TP
  2154. - -colors \fIn\fR
  2155. - Specify the maximum number of colors to use in the image.  This is a
  2156. - way to forcibly reduce the depth of an image.
  2157. - .TP
  2158.   -display \fIdisplay_name\fR
  2159.   X11 display name to send the image(s) to.
  2160.   .TP
  2161. --- 49,54 ----
  2162. ***************
  2163. *** 74,80 ****
  2164.   -onroot
  2165.   Load image(s) onto the root window instead of viewing in a window.
  2166.   This is the opposite of \fI-view\fR.  \fIXSetbg\fR has this option set
  2167. ! by default.
  2168.   .TP
  2169.   -path
  2170.   Displays the image path and image suffixes which will be used when
  2171. --- 76,83 ----
  2172.   -onroot
  2173.   Load image(s) onto the root window instead of viewing in a window.
  2174.   This is the opposite of \fI-view\fR.  \fIXSetbg\fR has this option set
  2175. ! by default.  Loading with the -onroot option will fail if enough
  2176. ! sharable colors cannot be allocated from the default colormap.
  2177.   .TP
  2178.   -path
  2179.   Displays the image path and image suffixes which will be used when
  2180. ***************
  2181. *** 93,98 ****
  2182. --- 96,106 ----
  2183.   image it's playing with and any special processing that it has to do. 
  2184.   This is the default for \fIxview\fR and \fIxloadimage\fR. 
  2185.   .TP
  2186. + -version
  2187. + Print the version number and patchlevel of this version of
  2188. + \fIxloadimage\fR.  Versions prior to version 1, patchlevel 03 do not
  2189. + have this option and should be updated.
  2190. + .TP
  2191.   -view
  2192.   View image(s) in a window.  This is the opposite of \fI-onroot\fR and
  2193.   the default for \fIxsetbg\fR. 
  2194. ***************
  2195. *** 100,105 ****
  2196. --- 108,119 ----
  2197.   The following options may preceed each image.  These options are
  2198.   local to the image they preceed. 
  2199.   .TP
  2200. + -at \fIX\fR,\fIY\fR
  2201. + Indicates coordinates to load the image at on the first image.  If
  2202. + this is an option to the first image, and the \fI-onroot\fR option is
  2203. + specified, the image will be loaded at the given location on the
  2204. + display background. 
  2205. + .TP
  2206.   -background \fIcolor\fR
  2207.   Use \fIcolor\fR as the background color instead of the default
  2208.   (usually white but this depends on the image type) if you are
  2209. ***************
  2210. *** 115,125 ****
  2211.   the first image, and the \fI-onroot\fR option is specified, the image
  2212.   will be centered on the display background. 
  2213.   .TP
  2214. ! -at \fIX\fR,\fIY\fR
  2215. ! Indicates coordinates to load the image at on the first image.  If
  2216. ! this is an option to the first image, and the \fI-onroot\fR option is
  2217. ! specified, the image will be loaded at the given location on the
  2218. ! display background. 
  2219.   .TP
  2220.   -clip \fIX\fR,\fIY\fR,\fIW\fR,\fIH\fR
  2221.   Clip the image before loading it.  \fIX\fR and \fIY\fR define the
  2222. --- 129,137 ----
  2223.   the first image, and the \fI-onroot\fR option is specified, the image
  2224.   will be centered on the display background. 
  2225.   .TP
  2226. ! -colors \fIn\fR
  2227. ! Specify the maximum number of colors to use in the image.  This is a
  2228. ! way to forcibly reduce the depth of an image.
  2229.   .TP
  2230.   -clip \fIX\fR,\fIY\fR,\fIW\fR,\fIH\fR
  2231.   Clip the image before loading it.  \fIX\fR and \fIY\fR define the
  2232. ***************
  2233. *** 161,173 ****
  2234.   .TP
  2235.   -zoom \fIpercentage\fR
  2236.   Zoom both the X and Y axes by \fIpercentage\fR.  See \fI-xzoom\fR for
  2237. ! more information. 
  2238.   .SH EXAMPLES
  2239.   To load the rasterfile "my.image" onto the background and replicate
  2240.   it to fill the entire background:
  2241.   .sp
  2242.   .ti +5
  2243. ! xloadimage my.image
  2244.   .PP
  2245.   To load a monochrome image "my.image" onto the background, using red
  2246.   as the foreground color, replicate the image, and overlay
  2247. --- 173,187 ----
  2248.   .TP
  2249.   -zoom \fIpercentage\fR
  2250.   Zoom both the X and Y axes by \fIpercentage\fR.  See \fI-xzoom\fR for
  2251. ! more information.  Technically the percentage actually zoomed is the
  2252. ! square of the number supplied since the zoom is to both axes, but I
  2253. ! opted for consistency instead of accuracy.
  2254.   .SH EXAMPLES
  2255.   To load the rasterfile "my.image" onto the background and replicate
  2256.   it to fill the entire background:
  2257.   .sp
  2258.   .ti +5
  2259. ! xloadimage -onroot my.image
  2260.   .PP
  2261.   To load a monochrome image "my.image" onto the background, using red
  2262.   as the foreground color, replicate the image, and overlay
  2263. ***************
  2264. *** 181,202 ****
  2265.   .sp
  2266.   .ti +5
  2267.   xloadimage -center -clip 10,10,100,0 my.image
  2268.   .SH PATHS AND EXTENSIONS
  2269. ! The file ~/.xloadimagerc (and optionally a system-wide file which is
  2270. ! system-specific) defines the path and default extensions that
  2271. ! .I xloadimage
  2272. ! will use when looking for images.  The file can have two statements:
  2273. ! "path=" and "extension=" (the equals signs must follow the word with
  2274. ! no spaces between).  Everything following the "path=" keyword
  2275. ! will be prepended to the supplied image name if the supplied name does
  2276. ! not specify an existing file.  The paths will be searched in the order
  2277. ! they are specified.  Everything following the "extension=" keyword
  2278. ! will be appended to the supplied image name if the supplied name does
  2279. ! not specify and existing file.  As with paths, these extensions will
  2280. ! be searched in the order they are given.  Comments are any portion of
  2281. ! a line following a hash-mark (#).  The following is a sample
  2282. ! ~/.xloadimagerc file:
  2283.   .PP
  2284.   .nf
  2285.     # paths to look for images in
  2286.     path= /usr/local/images
  2287. --- 195,287 ----
  2288.   .sp
  2289.   .ti +5
  2290.   xloadimage -center -clip 10,10,100,0 my.image
  2291. + .PP
  2292. + To double the size of an image:
  2293. + .sp
  2294. + .ti +5
  2295. + xloadimage -zoom 200 my.image
  2296. + .PP
  2297. + To halve the size of an image:
  2298. + .sp
  2299. + .ti +5
  2300. + xloadimage -zoom 50 my.image
  2301. + .PP
  2302. + To brighten a dark image:
  2303. + .sp
  2304. + .ti +5
  2305. + xloadimage -brighten 150 my.image
  2306. + .PP
  2307. + To darken a bright image:
  2308. + .sp
  2309. + .ti +5
  2310. + xloadimage -brighten 50 my.image
  2311. + .SH HINTS FOR GOOD IMAGE DISPLAYS
  2312. + Since images are likely to come from a variety of sources, they may be
  2313. + in a variety of aspect ratios which may not be supported by your
  2314. + display.  The \fI-xzoom\fR and \fI-yzoom\fR options can be used to
  2315. + change the aspect ratio of an image before display.  If you use these
  2316. + options, it is recommended that you increase the size of one of the
  2317. + dimensions instead of shrinking the other, since shrinking looses
  2318. + detail.  For instance, many GIF images have an X:Y ratio of about 2:1.
  2319. + You can correct this for viewing on a 1:1 display with either
  2320. + \fI-xzoom 50\fR or \fI-yzoom 200\fR (reduce X axis to 50% of its size
  2321. + and expand Y axis to 200% of its size, respectively) but the latter
  2322. + should be used so no detail is lost in the conversion.
  2323. + .PP
  2324. + When merging images, the first image loaded is used to determine the
  2325. + depth of the merged image.  This becomes a problem if the first image
  2326. + is monochrome and other images are color, since the other images will
  2327. + be dithered to monochrome before merging.  You can get around this
  2328. + behavior by using the \fI-geometry\fR option to specify the size of
  2329. + the destination image -- this will force \fIxloadimage\fR to use the
  2330. + default depth of the display instead of 1.  The standard behavior
  2331. + might be modified in the future if it becomes a problem.
  2332. + .PP
  2333. + You can perform image processing on a small portion of an image by
  2334. + loading the image more than once and using the \fI-at\fR and
  2335. + \fI-clip\fR options.  Load the image, then load it again and clip,
  2336. + position, and process the second.  To brighten a 100x100 rectangular
  2337. + portion of an image located at (50,50), for instance, you could type:
  2338. + .sp
  2339. + .ti +5
  2340. + xloadimage my.image -at 50,50 -clip 50,50,100,100 -brighten 150 my.image
  2341. + .PP
  2342. + One common use of \fIxloadimage\fR is to load images onto the root
  2343. + window.  Unfortunately there is no agreed-upon method of freeing some
  2344. + root window resources, such as colormap entries, nor is there a way to
  2345. + modify the root window colormap without confusing most window
  2346. + managers.  For this reason, \fIxloadimage\fR will not allow the
  2347. + loading of images onto the root window if it cannot allocate shared
  2348. + colors from the root window's colormap.  I suggest the avoidance of
  2349. + multiple color image loads onto the root window, as these eat up root
  2350. + window shareable colormap entries.  If you wish to have a slideshow,
  2351. + display the images in a window.  A future implementation of
  2352. + \fIxloadimage\fR will have a \fI-fullscreen\fR (or maybe
  2353. + \fI-slideshow\fR) option, but this is as yet unavailable.
  2354. + .PP
  2355. + One common complaint is that \fIxloadimage\fR does not have a
  2356. + \fI-reverse\fR function for inverting monochrome images.  In fact,
  2357. + this function is a special-case of the foreground and background
  2358. + coloring options.  To invert an image with a black foreground and
  2359. + white background (which is standard), use \fI-foreground white
  2360. + -background black\fR.  This will work on both color and monochrome
  2361. + displays.
  2362.   .SH PATHS AND EXTENSIONS
  2363. ! The file ~/.xloadimagerc (and optionally a system-wide file) defines
  2364. ! the path and default extensions that \fIxloadimage\fR will use when
  2365. ! looking for images.  This file can have two statements: "path=" and
  2366. ! "extension=" (the equals signs must follow the word with no spaces
  2367. ! between).  Everything following the "path=" keyword will be prepended
  2368. ! to the supplied image name if the supplied name does not specify an
  2369. ! existing file.  The paths will be searched in the order they are
  2370. ! specified.  Everything following the "extension=" keyword will be
  2371. ! appended to the supplied image name if the supplied name does not
  2372. ! specify an existing file.  As with paths, these extensions will be
  2373. ! searched in the order they are given.  Comments are any portion of a
  2374. ! line following a hash-mark (#).
  2375.   .PP
  2376. + The following is a sample ~/.xloadimagerc file:
  2377. + .PP
  2378.   .nf
  2379.     # paths to look for images in
  2380.     path= /usr/local/images
  2381. ***************
  2382. *** 206,216 ****
  2383. --- 291,309 ----
  2384.     # default extensions for images; .Z is automatic; scanned in order
  2385.     extension= .csun .msun .sun .face .xbm .bm
  2386.   .fi
  2387. + .PP
  2388. + Versions of \fIxloadimage\fR prior to version 01, patchlevel 03 would
  2389. + load the system-wide file (if any), followed by the user's file.  This
  2390. + behavior made it difficult for the user to configure her environment
  2391. + if she didn't want the default.  Newer versions will ignore the
  2392. + system-wide file if a personal configuration file exists.
  2393.   .SH IMAGE TYPES
  2394.   .PP
  2395.   \fIXloadimage\fR currently supports the following image types:
  2396. + .sp
  2397.   .nf
  2398.     Faces Project images
  2399. +   GIF images
  2400.     Portable Bitmap (PBM) images
  2401.     Sun monochrome rasterfiles
  2402.     Sun color RGB rasterfiles
  2403. ***************
  2404. *** 219,247 ****
  2405.     X pixmap files
  2406.   .fi
  2407.   .PP
  2408. ! Both normal and compact PBM images are supported.  Both standard and
  2409. ! run-length encoded Sun rasterfiles are supported.
  2410.   .SH AUTHOR
  2411.   .nf
  2412.   Jim Frost
  2413. ! Software Tool & Die
  2414. ! madd@std.com
  2415.   .fi
  2416.   .SH BUGS
  2417. ! Zooming dithered images is UGLY.
  2418.   .PP
  2419. ! Loading images onto the root with PseudoColor or GrayScale displays
  2420. ! can cause colormap problems (and may interfere with window manager
  2421. ! operation) if there are not enough colors in the default colormap to
  2422. ! allocate all of the colors read/write.  This can happen on images
  2423. ! which have too many unique colors or if images are loaded onto the
  2424. ! root in succession.  Since there is currently no X standard for
  2425. ! changing the root colormap, this problem may or may not be corrected
  2426. ! in the future.
  2427.   .PP
  2428. ! Since \fIxloadimage\fR does not want a window larger than the image to
  2429. ! be displayed, it resizes the window to fit the image if the window
  2430. ! manager resizes the window to a size which is too large.  This could
  2431. ! cause a conflict if the window manager responds to the resize request
  2432. ! by resizing the window to the larger size.  This should be rare given
  2433. ! the state of current window managers and has never been observed.
  2434. --- 312,401 ----
  2435.     X pixmap files
  2436.   .fi
  2437.   .PP
  2438. ! Normal, compact, and raw PBM images are supported.  Both standard and
  2439. ! run-length encoded Sun rasterfiles are supported.  Any image whose
  2440. ! name ends in .Z is assumed to be a compressed image and will be
  2441. ! filtered through "uncompress".
  2442.   .SH AUTHOR
  2443.   .nf
  2444.   Jim Frost
  2445. ! Saber Software
  2446. ! jimf@saber.com
  2447.   .fi
  2448. + .PP
  2449. + Other contributing people include Barry Shein (bzs@std.com), Kirk L.
  2450. + Johnson (tuna@athena.mit.edu), Mark Snitilly (zok!mark@apple.com), and
  2451. + W. David Higgins (wdh@mkt.csd.harris.com).
  2452. + .SH FILES
  2453. + .nf
  2454. + .in +5
  2455. + xloadimage            - the image loader and viewer
  2456. + xsetbg                - pseudonym which quietly sets the background
  2457. + xview                 - pseudonym which views in a window
  2458. + /usr/lib/xloadimagerc - default system-wide configuration file
  2459. + ~/.xloadimagerc       - user's personal configuration file
  2460. + .in -5
  2461. + .fi
  2462. + .SH COPYRIGHT
  2463. + Copyright (c) 1989, 1990 Jim Frost and others.
  2464. + .PP
  2465. + \fIXloadimage\fR is copywritten material with a very loose copyright
  2466. + allowing unlimited modification and distribution if the copyright
  2467. + notices are left intact.  Various portions are copywritten by various
  2468. + people, but all use a modification of the MIT copyright notice.
  2469. + Please check the source for complete copyright information.  The
  2470. + intent is to keep the source free, not to stifle its distribution, so
  2471. + please write to me if you have any questions.
  2472.   .SH BUGS
  2473. ! Zooming dithered images, especially downwards, is UGLY.
  2474.   .PP
  2475. ! The dithering algorithm used by \fI-dither\fR could be better, and
  2476. ! both \fI-dither\fR and \fI-halftone\fR assume that a color's
  2477. ! brightness is the sum of its RGB values, which is not correct but has
  2478. ! the advantage of being simple and fast.
  2479.   .PP
  2480. ! Images can come in a variety of aspect ratios.  \fIXloadimage\fR cannot
  2481. ! detect what aspect ratio the particular image being loaded has, nor
  2482. ! the aspect ratio of the destination display, so images with differing
  2483. ! aspect ratios from the destination display will appear distorted.  See
  2484. ! \fIHINTS FOR GOOD IMAGE DISPLAYS\fR for more information.
  2485. ! .PP
  2486. ! The GIF format allows more than one image to be stored in a single GIF
  2487. ! file, but \fIxloadimage\fR will only display the first.
  2488. ! .PP
  2489. ! Only PseudoColor, GrayScale, StaticColor, and StaticGray visuals are
  2490. ! supported.  These are the most common visuals so this isn't usually a
  2491. ! problem.
  2492. ! .PP
  2493. ! You cannot load an image onto the root window if the default visual is
  2494. ! not supported by \fIxloadimage\fR.
  2495. ! .PP
  2496. ! If color images with substantially differing colormaps are loaded onto
  2497. ! the root window, eventually there will be no more sharable colors in
  2498. ! the default colormap and subsequent image loads onto the root window
  2499. ! will fail.  This is the result of limitations within X and a lack of
  2500. ! any protocol for handling root window and/or default colormap changes.
  2501. ! .PP
  2502. ! One of the pseudonyms for \fIxloadimage\fR, \fIxview\fR, is the same
  2503. ! name as Sun uses for their SunView-under-X package.  This will be
  2504. ! confusing if you're one of those poor souls who has to use Sun's
  2505. ! XView.
  2506. ! .PP
  2507. ! Some window managers do not correctly handle window size requests.  In
  2508. ! particular, versions of the twm window manager prior to X11R4 will use
  2509. ! the MaxSize hint instead of the PSize hint, causing images which
  2510. ! are larger than the screen to display in a window larger than the
  2511. ! screen, something which is normally avoided.  These versions of twm
  2512. ! also ignore the MaxSize argument's real function, to limit the maximum
  2513. ! size of the window, and allow the window to be resized larger than the
  2514. ! image.  If this happens, \fIxloadimage\fR merely places the image in
  2515. ! the upper-left corner of the window and uses the zero-value'ed pixel
  2516. ! for any space which is not covered by the image.  This behavior is
  2517. ! less-than-graceful but so are window managers which are cruel enough
  2518. ! to ignore such details.
  2519. ! .PP
  2520. ! The order in which operations are performed on an image is independent
  2521. ! of the order in which they were specified on the command line.
  2522. ! Wherever possible I tried to order operations in such a way as to look
  2523. ! the best possible (zooming before dithering, for instance) or to
  2524. ! increase speed (zooming downward before compressing, for instance).
  2525. diff -c xloadimage.02/xpixmap.c xloadimage.03/xpixmap.c
  2526. *** xloadimage.02/xpixmap.c    Sun Dec 31 16:01:52 1989
  2527. --- xloadimage.03/xpixmap.c    Wed Dec  6 15:17:31 1989
  2528. ***************
  2529. *** 39,44 ****
  2530. --- 39,45 ----
  2531.     char           buf[BUFSIZ];
  2532.     char           what[BUFSIZ];
  2533.     char          *p;
  2534. +   char          *imagetitle;
  2535.     unsigned int   value;
  2536.     unsigned int   format;  /* image format */
  2537.     unsigned int   w, h;    /* image dimensions */
  2538. ***************
  2539. *** 112,132 ****
  2540.   
  2541.     if (p= rindex(what, '_')) {     /* get the name in the image if there is */
  2542.       *p= '\0';                     /* one */
  2543. !     image->title= dupString(what);
  2544.     }
  2545.     else {
  2546.       p= what;
  2547. !     image->title= dupString(name);
  2548.     }
  2549.   
  2550.     if (verbose)
  2551.       printf("%s is a %dx%d X Pixmap image with %d colors titled '%s'\n",
  2552. !        name, w, h, ncolors, image->title);
  2553.   
  2554.     for (depth= 1, value= 2; value < ncolors; value <<= 1, depth++)
  2555.       ;
  2556.     image= newRGBImage(w, h, depth);
  2557.     image->rgb.used= ncolors;
  2558.   
  2559.     /* read the colors array and build the image colormap
  2560.      */
  2561. --- 113,134 ----
  2562.   
  2563.     if (p= rindex(what, '_')) {     /* get the name in the image if there is */
  2564.       *p= '\0';                     /* one */
  2565. !     imagetitle= dupString(what);
  2566.     }
  2567.     else {
  2568.       p= what;
  2569. !     imagetitle= dupString(name);
  2570.     }
  2571.   
  2572.     if (verbose)
  2573.       printf("%s is a %dx%d X Pixmap image with %d colors titled '%s'\n",
  2574. !        name, w, h, ncolors, imagetitle);
  2575.   
  2576.     for (depth= 1, value= 2; value < ncolors; value <<= 1, depth++)
  2577.       ;
  2578.     image= newRGBImage(w, h, depth);
  2579.     image->rgb.used= ncolors;
  2580. +   image->title= dupString(imagetitle);
  2581.   
  2582.     /* read the colors array and build the image colormap
  2583.      */
  2584. ***************
  2585. *** 227,235 ****
  2586.   }
  2587.   
  2588.   int xpixmapIdent(fullname, name)
  2589.   { Image *image;
  2590.   
  2591. !   if (image= xpixmapLoad(fullname, name, 1)) {
  2592.       freeImage(image);
  2593.       return(1);
  2594.     }
  2595. --- 229,238 ----
  2596.   }
  2597.   
  2598.   int xpixmapIdent(fullname, name)
  2599. +      char *fullname, *name;
  2600.   { Image *image;
  2601.   
  2602. !   if (image= xpixmapLoad(fullname, name, (unsigned int)1)) {
  2603.       freeImage(image);
  2604.       return(1);
  2605.     }
  2606. diff -c xloadimage.02/zio.c xloadimage.03/zio.c
  2607. *** xloadimage.02/zio.c    Mon Nov  6 10:52:00 1989
  2608. --- xloadimage.03/zio.c    Wed Dec  6 15:19:19 1989
  2609. ***************
  2610. *** 16,27 ****
  2611.   { ZFILE *zf;
  2612.     char   buf[BUFSIZ];
  2613.   
  2614. !   zf= (ZFILE *)lmalloc(sizeof(ZFILE));
  2615.     if ((strlen(name) > 2) && !strcmp(".Z", name + (strlen(name) - 2))) {
  2616.       zf->type= ZPIPE;
  2617.       sprintf(buf, "uncompress -c %s", name);
  2618.       if (! (zf->stream= popen(buf, "r"))) {
  2619. !       lfree(zf);
  2620.         return(NULL);
  2621.       }
  2622.       return(zf);
  2623. --- 16,27 ----
  2624.   { ZFILE *zf;
  2625.     char   buf[BUFSIZ];
  2626.   
  2627. !   zf= (ZFILE *)lmalloc((unsigned int)sizeof(ZFILE));
  2628.     if ((strlen(name) > 2) && !strcmp(".Z", name + (strlen(name) - 2))) {
  2629.       zf->type= ZPIPE;
  2630.       sprintf(buf, "uncompress -c %s", name);
  2631.       if (! (zf->stream= popen(buf, "r"))) {
  2632. !       lfree((byte *)zf);
  2633.         return(NULL);
  2634.       }
  2635.       return(zf);
  2636. ***************
  2637. *** 28,34 ****
  2638.     }
  2639.     zf->type= ZSTANDARD;
  2640.     if (! (zf->stream= fopen(name, "r"))) {
  2641. !     lfree(zf);
  2642.       return(NULL);
  2643.     }
  2644.     return(zf);
  2645. --- 28,34 ----
  2646.     }
  2647.     zf->type= ZSTANDARD;
  2648.     if (! (zf->stream= fopen(name, "r"))) {
  2649. !     lfree((byte *)zf);
  2650.       return(NULL);
  2651.     }
  2652.     return(zf);
  2653. ***************
  2654. *** 73,77 ****
  2655.       printf("zclose: bad ZFILE structure\n");
  2656.       exit(1);
  2657.     }
  2658. !   lfree(zf);
  2659.   }
  2660. --- 73,77 ----
  2661.       printf("zclose: bad ZFILE structure\n");
  2662.       exit(1);
  2663.     }
  2664. !   lfree((byte *)zf);
  2665.   }
  2666. diff -c xloadimage.02/zoom.c xloadimage.03/zoom.c
  2667. *** xloadimage.02/zoom.c    Sun Dec 31 16:03:16 1989
  2668. --- xloadimage.03/zoom.c    Wed Dec  6 15:21:20 1989
  2669. ***************
  2670. *** 162,169 ****
  2671.     }
  2672.   
  2673.     image->title= dupString(buf);
  2674. !   lfree(xindex);
  2675. !   lfree(yindex);
  2676.     if (verbose)
  2677.       printf("done\n");
  2678.     return(image);
  2679. --- 162,169 ----
  2680.     }
  2681.   
  2682.     image->title= dupString(buf);
  2683. !   lfree((byte *)xindex);
  2684. !   lfree((byte *)yindex);
  2685.     if (verbose)
  2686.       printf("done\n");
  2687.     return(image);
  2688.  
  2689. dan
  2690. -----------------------------------------------------------
  2691.             O'Reilly && Associates
  2692.         argv@sun.com / argv@ora.com
  2693.        632 Petaluma Ave, Sebastopol, CA 95472 
  2694.      800-338-NUTS, in CA: 800-533-NUTS, FAX 707-829-0104
  2695.     Opinions expressed reflect those of the author only.
  2696.